landfound / welly

Automatically exported from code.google.com/p/welly
GNU General Public License v2.0
0 stars 0 forks source link

Wrong line selected in fullscreen mode #58

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Find a font size / screen resolution combination that will cause Welly to 
leave some space at the top and bottom of the screen after going into 
fullscreen mode.  For me, this was 1280x800 and the default font sizes.
2. Enter fullscreen mode
3. Select some text by left clicking and dragging

What is the expected output? What do you see instead?
The line above the cursor is selected instead of the current line.  

What version of the product are you using? On what operating system?
OS X 10.6.7, Welly v2.64 (release 825)
Issue became apparent after upgrading to 2.64

Please provide any additional information below.
The frame origin is grabbed and used to calculate a row offset in 
WLTerminalView:convertIndexFromPoint:.  From what I can tell, this function is 
getting the frame of the WLTerminal instead of the view that is set when doing 
the font conversion, WLTabView.  
The patch below fixes the problem for my use case:

Index: WLTerminalView.m
===================================================================
--- WLTerminalView.m    (revision 832)
+++ WLTerminalView.m    (working copy)
@@ -93,7 +93,7 @@

 - (int)convertIndexFromPoint:(NSPoint)p {
    // The following 2 lines: for full screen mode
-   NSRect frame = [self frame];
+   NSRect frame = [[self superview] frame];
    p.y -= 2 * frame.origin.y;

     if (p.x >= _maxColumn * _fontWidth) p.x = _maxColumn * _fontWidth - 0.001;

Original issue reported on code.google.com by ryan.ch...@gmail.com on 2 May 2011 at 2:03

GoogleCodeExporter commented 9 years ago
Just realized this fix affects rangeForWordAtPoint: in the same class, which 
ends up with a row 1 too low.  Looking into it now.

Original comment by ryan.ch...@gmail.com on 2 May 2011 at 2:57

GoogleCodeExporter commented 9 years ago
OK, there was an inconsistency between the points that convertIndexFromPoint 
was being called with.  This fix works, as far as I can tell, for all use cases 
in both normal and fullscreen mode, even when fullscreen is not scaled to fit 
vertically. :)

Sorry if my solutions are not ideal; I'm new to Cocoa programming.

Index: WLTerminalView.m
===================================================================
--- WLTerminalView.m    (revision 832)
+++ WLTerminalView.m    (working copy)
@@ -92,10 +92,6 @@
 #pragma mark Conversion

 - (int)convertIndexFromPoint:(NSPoint)p {
-   // The following 2 lines: for full screen mode
-   NSRect frame = [self frame];
-   p.y -= 2 * frame.origin.y;
-   
     if (p.x >= _maxColumn * _fontWidth) p.x = _maxColumn * _fontWidth - 0.001;
     if (p.y >= _maxRow * _fontHeight) p.y = _maxRow * _fontHeight - 0.001;
     if (p.x < 0) p.x = 0;
@@ -509,7 +505,8 @@
    // Disable the mouse if we cancelled any selection
     if(abs(_selectionLength) > 0) 
         _isNotCancelingSelection = NO;
-    NSPoint p = [self convertPoint:[theEvent locationInWindow] toView:nil];
+   NSPoint p = [NSEvent mouseLocation];
+   p = [self convertPoint:[[self window] convertScreenToBase:p] fromView:nil];
     _selectionLocation = [self convertIndexFromPoint:p];
     _selectionLength = 0;

@@ -531,8 +528,8 @@
        return;
    }

-    NSPoint p = [theEvent locationInWindow];
-    p = [self convertPoint:p toView:nil];
+   NSPoint p = [NSEvent mouseLocation];
+   p = [self convertPoint:[[self window] convertScreenToBase:p] fromView:nil];
     int index = [self convertIndexFromPoint:p];
     int oldValue = _selectionLength;
     _selectionLength = index - _selectionLocation + 1;

Original comment by ryan.ch...@gmail.com on 2 May 2011 at 5:24