From 7d1592daa3cd4603257328cdb3e6e5b1c8213c20 Mon Sep 17 00:00:00 2001 From: Alexander Malmberg Date: Sun, 9 Feb 2003 14:26:10 +0000 Subject: [PATCH] Fix some broken movement actions. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@15914 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 6 +++++ Source/NSTextView_actions.m | 44 +++++++++++++++++++------------------ 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index edc665439..7a29611b5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2003-02-09 15:23 Alexander Malmberg + + * Source/NSTextView_actions.m: Fix several movement actions (used + to move from the wrong end of the selected range, or mixed glyphs + and characters). + 2003-02-09 14:48 Alexander Malmberg * Source/GSHorizontalTypesetter.m: Make the main method reentrant diff --git a/Source/NSTextView_actions.m b/Source/NSTextView_actions.m index 325e7edd1..7cfe4b04e 100644 --- a/Source/NSTextView_actions.m +++ b/Source/NSTextView_actions.m @@ -863,7 +863,7 @@ check if there was a reason for that. -(void) moveWordBackward: (id)sender { unsigned int newLocation; - newLocation = [_textStorage nextWordFromIndex: _layoutManager->_selected_range.location + newLocation = [_textStorage nextWordFromIndex: [self _movementOrigin] forward: NO]; [self _moveTo: newLocation select: NO]; @@ -871,7 +871,7 @@ check if there was a reason for that. -(void) moveWordBackwardAndModifySelection: (id)sender { unsigned int newLocation; - newLocation = [_textStorage nextWordFromIndex: _layoutManager->_selected_range.location + newLocation = [_textStorage nextWordFromIndex: [self _movementOrigin] forward: NO]; [self _moveTo: newLocation select: YES]; @@ -880,7 +880,7 @@ check if there was a reason for that. -(void) moveWordForward: (id)sender { unsigned newLocation; - newLocation = [_textStorage nextWordFromIndex: _layoutManager->_selected_range.location + newLocation = [_textStorage nextWordFromIndex: [self _movementOrigin] forward: YES]; [self _moveTo: newLocation select: NO]; @@ -888,10 +888,10 @@ check if there was a reason for that. -(void) moveWordForwardAndModifySelection: (id)sender { unsigned newLocation; - newLocation = [_textStorage nextWordFromIndex: _layoutManager->_selected_range.location - forward: NO]; + newLocation = [_textStorage nextWordFromIndex: [self _movementOrigin] + forward: YES]; [self _moveTo: newLocation - select: NO]; + select: YES]; } -(void) moveToBeginningOfDocument: (id)sender @@ -910,8 +910,9 @@ check if there was a reason for that. { NSRange aRange; - aRange = [[_textStorage string] lineRangeForRange: _layoutManager->_selected_range]; - [self setSelectedRange: NSMakeRange (aRange.location, 0)]; + aRange = [[_textStorage string] lineRangeForRange: NSMakeRange([self _movementOrigin], 0)]; + [self _moveTo: aRange.location + select: NO]; } -(void) moveToEndOfParagraph: (id)sender @@ -920,7 +921,7 @@ check if there was a reason for that. unsigned newLocation; unsigned maxRange; - aRange = [[_textStorage string] lineRangeForRange: _layoutManager->_selected_range]; + aRange = [[_textStorage string] lineRangeForRange: NSMakeRange([self _movementOrigin], 0)]; maxRange = NSMaxRange (aRange); if (maxRange == 0) @@ -963,7 +964,8 @@ check if there was a reason for that. newLocation = aRange.location; } - [self setSelectedRange: NSMakeRange (newLocation, 0) ]; + [self _moveTo: newLocation + select: NO]; } @@ -1089,18 +1091,18 @@ and layout is left-to-right */ -(void) selectLine: (id)sender { - if ([_textStorage length] > 0) - { - NSRange aRange; - NSRect ignored; + unsigned int start, end, cindex; - /* TODO: broken. assumes glyph==character */ - ignored = [_layoutManager lineFragmentRectForGlyphAtIndex: - _layoutManager->_selected_range.location - effectiveRange: &aRange]; - - [self setSelectedRange: aRange]; - } + cindex = [self _movementOrigin]; + start = [_layoutManager characterIndexMoving: GSInsertionPointMoveLeft + fromCharacterIndex: cindex + originalCharacterIndex: cindex + distance: 1e8]; + end = [_layoutManager characterIndexMoving: GSInsertionPointMoveRight + fromCharacterIndex: cindex + originalCharacterIndex: cindex + distance: 1e8]; + [self setSelectedRange: NSMakeRange(start, end - start)]; }