* Source/NSTextView_actions.m: Change cursor movement implementations

when collapsing a selection.
        * Source/NSParagraphStyle.m (-setBaseWritingDirection:): Add comment.
        * Source/NSAttributedString: Add and remove characters in the word
        break character set.
        * KeyBindings/DefaultKeyBindings.dict: Change control-f and control-b
        to moveForward: and moveBackward:



git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@24136 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
ratmice 2006-11-20 16:20:15 +00:00
parent 65f7efa8fd
commit d3895d8f14
5 changed files with 207 additions and 37 deletions

View file

@ -1,3 +1,14 @@
2006-11-20 Matt Rice <ratmice@gmail.com>
* Source/NSTextView_actions.m: Change cursor movement implementations
when collapsing a selection.
* Source/NSParagraphStyle.m (-setBaseWritingDirection:): Add comment.
* Source/NSAttributedString: Add and remove characters in the word
break character set.
* KeyBindings/DefaultKeyBindings.dict: Change control-f and control-b
to moveForward: and moveBackward:
2006-11-19 Richard Frith-Macdoanld <rfm@gnu.org> 2006-11-19 Richard Frith-Macdoanld <rfm@gnu.org>
* Source/NSAffineTransform.m: * Source/NSAffineTransform.m:

View file

@ -51,10 +51,10 @@
/* Emacs Control keybindings */ /* Emacs Control keybindings */
"Control-a" = "moveToBeginningOfLine:"; "Control-a" = "moveToBeginningOfLine:";
"Control-b" = "moveLeft:"; "Control-b" = "moveBackward:";
"Control-d" = "deleteForward:"; "Control-d" = "deleteForward:";
"Control-e" = "moveToEndOfLine:"; "Control-e" = "moveToEndOfLine:";
"Control-f" = "moveRight:"; "Control-f" = "moveForward:";
"Control-h" = "deleteBackward:"; "Control-h" = "deleteBackward:";
/* "Control-l" = "centerSelectionInVisibleArea:"; */ /* "Control-l" = "centerSelectionInVisibleArea:"; */
"Control-k" = "deleteToEndOfLine:"; "Control-k" = "deleteToEndOfLine:";

View file

@ -78,7 +78,8 @@ static void cache_init_real(void)
[m formUnionWithCharacterSet: cset]; [m formUnionWithCharacterSet: cset];
cset = [NSCharacterSet illegalCharacterSet]; cset = [NSCharacterSet illegalCharacterSet];
[m formUnionWithCharacterSet: cset]; [m formUnionWithCharacterSet: cset];
[m removeCharactersInString: @"-"]; [m addCharactersInString: @"<>"];
[m removeCharactersInString: @"_"];
wordBreakCSet = [m copy]; wordBreakCSet = [m copy];
RELEASE (m); RELEASE (m);

View file

@ -514,6 +514,19 @@ static NSParagraphStyle *defaultStyle = nil;
- (void) setBaseWritingDirection: (NSWritingDirection)direction - (void) setBaseWritingDirection: (NSWritingDirection)direction
{ {
/*
* FIXME there is some confusion regarding natural writing direction.
*
* this method is documented as setting
* NSWritingDirectionLeftToRight or NSWritingDirectionRightToLeft
* based on the users language preferences.
* when encountering NSWritingDirectionNaturalDirection
*
* NSWritingDirectionNatural constant is documented as using the
* unicode bidi algorithm.
*
* no idea what the constant name or behaviour actually is.
*/
_baseDirection = direction; _baseDirection = direction;
} }

View file

@ -52,6 +52,7 @@
#include "AppKit/NSScrollView.h" #include "AppKit/NSScrollView.h"
#include "AppKit/NSTextStorage.h" #include "AppKit/NSTextStorage.h"
#include "AppKit/NSTextView.h" #include "AppKit/NSTextView.h"
#include "AppKit/NSParagraphStyle.h"
/* /*
These methods are for user actions, ie. they are normally called from These methods are for user actions, ie. they are normally called from
@ -761,11 +762,11 @@ added to the selection (1,3).
[self scrollRangeToVisible: NSMakeRange(cindex, 0)]; [self scrollRangeToVisible: NSMakeRange(cindex, 0)];
} }
- (void) _move: (GSInsertionPointMovementDirection)direction - (void) _moveFrom: (unsigned int)cindex
distance: (float)distance direction: (GSInsertionPointMovementDirection)direction
select: (BOOL)select distance: (float)distance
select: (BOOL)select
{ {
unsigned int cindex;
int new_direction; int new_direction;
if (direction == GSInsertionPointMoveUp || if (direction == GSInsertionPointMoveUp ||
@ -783,7 +784,6 @@ added to the selection (1,3).
new_direction = 0; new_direction = 0;
} }
cindex = [self _movementOrigin];
if (new_direction != _currentInsertionPointMovementDirection || if (new_direction != _currentInsertionPointMovementDirection ||
!new_direction) !new_direction)
{ {
@ -801,6 +801,64 @@ added to the selection (1,3).
_currentInsertionPointMovementDirection = new_direction; _currentInsertionPointMovementDirection = new_direction;
} }
- (void) _move: (GSInsertionPointMovementDirection)direction
distance: (float)distance
select: (BOOL)select
{
[self _moveFrom: [self _movementOrigin]
direction: direction
distance: distance
select: select];
}
/*
* returns the character index for the left or right side of the selected text
* based upon the writing direction of the paragraph style.
* it should only be used when moving a literal direction such as left right
* up or down, not directions like forward, backward, beginning or end
*/
- (unsigned int) _characterIndexForSelectedRange: (NSRange)range
direction: (GSInsertionPointMovementDirection)direction
{
unsigned int cIndex;
NSParagraphStyle *parStyle;
NSWritingDirection writingDirection;
parStyle = [[self typingAttributes]
objectForKey: NSParagraphStyleAttributeName];
writingDirection = [parStyle baseWritingDirection];
switch (writingDirection)
{
case NSWritingDirectionLeftToRight:
cIndex = (direction == GSInsertionPointMoveLeft
|| direction == GSInsertionPointMoveUp)
? range.location
: NSMaxRange(range);
break;
case NSWritingDirectionRightToLeft:
cIndex = (direction == GSInsertionPointMoveLeft
|| direction == GSInsertionPointMoveUp)
? NSMaxRange(range)
: range.location;
break;
case NSWritingDirectionNaturalDirection:
// not sure if we should see this as it should resolve to either
// LeftToRight or RightToLeft in NSParagraphStyle
// for the users language.
//
// currently falls back to default..
default:
/* default to LeftToRight */
cIndex = (direction == GSInsertionPointMoveLeft
|| direction == GSInsertionPointMoveUp)
? range.location
: NSMaxRange(range);
break;
}
return cIndex;
}
/* /*
Insertion point movement actions. Insertion point movement actions.
@ -811,7 +869,12 @@ check if there was a reason for that.
- (void) moveUp: (id)sender - (void) moveUp: (id)sender
{ {
[self _move: GSInsertionPointMoveUp NSRange range = [self selectedRange];
unsigned int cIndex = [self _characterIndexForSelectedRange:range
direction:GSInsertionPointMoveUp];
[self _moveFrom: cIndex
direction: GSInsertionPointMoveUp
distance: 0.0 distance: 0.0
select: NO]; select: NO];
} }
@ -825,7 +888,11 @@ check if there was a reason for that.
- (void) moveDown: (id)sender - (void) moveDown: (id)sender
{ {
[self _move: GSInsertionPointMoveDown NSRange range = [self selectedRange];
unsigned int cIndex = [self _characterIndexForSelectedRange: range
direction: GSInsertionPointMoveDown];
[self _moveFrom: cIndex
direction: GSInsertionPointMoveDown
distance: 0.0 distance: 0.0
select: NO]; select: NO];
} }
@ -839,26 +906,56 @@ check if there was a reason for that.
- (void) moveLeft: (id)sender - (void) moveLeft: (id)sender
{ {
[self _move: GSInsertionPointMoveLeft NSRange range = [self selectedRange];
distance: 0.0
select: NO]; if (range.length)
{
unsigned int cIndex;
cIndex = [self _characterIndexForSelectedRange: range
direction:GSInsertionPointMoveLeft];
[self _moveTo: cIndex select: NO];
}
else
{
[self _move: GSInsertionPointMoveLeft
distance: 0.0
select: NO];
}
} }
- (void) moveRight: (id)sender - (void) moveRight: (id)sender
{ {
[self _move: GSInsertionPointMoveRight NSRange range = [self selectedRange];
distance: 0.0
select: NO]; if (range.length)
{
unsigned int cIndex;
cIndex = [self _characterIndexForSelectedRange: range
direction: GSInsertionPointMoveRight];
[self _moveTo: cIndex select: NO];
}
else
{
[self _move: GSInsertionPointMoveRight
distance: 0.0
select: NO];
}
} }
- (void) moveBackward: (id)sender - (void) moveBackward: (id)sender
{ {
unsigned int to = [self _movementOrigin]; NSRange range = [self selectedRange];
unsigned int to = range.location;
if (to == 0) if (range.length == 0 && to)
return; {
to--; to--;
}
[self _moveTo: to [self _moveTo: to
select: NO]; select: NO];
} }
@ -876,14 +973,18 @@ check if there was a reason for that.
- (void) moveForward: (id)sender - (void) moveForward: (id)sender
{ {
unsigned int to = [self _movementOrigin]; NSRange range = [self selectedRange];
unsigned int to = NSMaxRange(range);
if (to == [_textStorage length])
return; if (range.length == 0 && to != [_textStorage length])
to++; {
to++;
}
[self _moveTo: to [self _moveTo: to
select: NO]; select: NO];
} }
- (void) moveForwardAndModifySelection: (id)sender - (void) moveForwardAndModifySelection: (id)sender
{ {
unsigned int to = [self _movementOrigin]; unsigned int to = [self _movementOrigin];
@ -897,9 +998,11 @@ check if there was a reason for that.
- (void) moveWordBackward: (id)sender - (void) moveWordBackward: (id)sender
{ {
NSRange range = [self selectedRange];
unsigned int newLocation; unsigned int newLocation;
unsigned int cIndex = range.location;
newLocation = [_textStorage nextWordFromIndex: [self _movementOrigin]
newLocation = [_textStorage nextWordFromIndex: cIndex
forward: NO]; forward: NO];
[self _moveTo: newLocation [self _moveTo: newLocation
select: NO]; select: NO];
@ -918,8 +1021,9 @@ check if there was a reason for that.
- (void) moveWordForward: (id)sender - (void) moveWordForward: (id)sender
{ {
unsigned newLocation; unsigned newLocation;
unsigned int cIndex = NSMaxRange([self selectedRange]);
newLocation = [_textStorage nextWordFromIndex: [self _movementOrigin] newLocation = [_textStorage nextWordFromIndex: cIndex
forward: YES]; forward: YES];
[self _moveTo: newLocation [self _moveTo: newLocation
select: NO]; select: NO];
@ -961,10 +1065,11 @@ check if there was a reason for that.
- (void) moveToBeginningOfParagraph: (id)sender - (void) moveToBeginningOfParagraph: (id)sender
{ {
NSRange aRange; NSRange aRange = [self selectedRange];
aRange = [[_textStorage string] lineRangeForRange: aRange = [[_textStorage string] lineRangeForRange:
NSMakeRange([self _movementOrigin], 0)]; NSMakeRange(aRange.location, 0)];
[self _moveTo: aRange.location [self _moveTo: aRange.location
select: NO]; select: NO];
} }
@ -984,9 +1089,19 @@ check if there was a reason for that.
NSRange aRange; NSRange aRange;
unsigned newLocation; unsigned newLocation;
unsigned maxRange; unsigned maxRange;
unsigned int cIndex;
if (flag)
{
cIndex = [self _movementOrigin];
}
else
{
cIndex = NSMaxRange([self selectedRange]);
}
aRange = [[_textStorage string] lineRangeForRange: aRange = [[_textStorage string] lineRangeForRange:
NSMakeRange([self _movementOrigin], 0)]; NSMakeRange(cIndex, 0)];
maxRange = NSMaxRange (aRange); maxRange = NSMaxRange (aRange);
if (maxRange == 0) if (maxRange == 0)
@ -1047,7 +1162,11 @@ check if there was a reason for that.
and layout is left-to-right */ and layout is left-to-right */
- (void) moveToBeginningOfLine: (id)sender - (void) moveToBeginningOfLine: (id)sender
{ {
[self _move: GSInsertionPointMoveLeft NSRange range = [self selectedRange];
unsigned int cIndex = range.location;
[self _moveFrom: cIndex
direction: GSInsertionPointMoveLeft
distance: 1e8 distance: 1e8
select: NO]; select: NO];
} }
@ -1061,7 +1180,10 @@ and layout is left-to-right */
- (void) moveToEndOfLine: (id)sender - (void) moveToEndOfLine: (id)sender
{ {
[self _move: GSInsertionPointMoveRight unsigned int cIndex = NSMaxRange([self selectedRange]);
[self _moveFrom: cIndex
direction: GSInsertionPointMoveRight
distance: 1e8 distance: 1e8
select: NO]; select: NO];
} }
@ -1084,6 +1206,17 @@ and layout is left-to-right */
float scrollDelta; float scrollDelta;
float oldOriginY; float oldOriginY;
float newOriginY; float newOriginY;
unsigned int cIndex;
if (flag)
{
cIndex = [self _movementOrigin];
}
else
{
cIndex = [self _characterIndexForSelectedRange: [self selectedRange]
direction: GSInsertionPointMoveDown];
}
/* /*
* Scroll; also determine how far to move the insertion point. * Scroll; also determine how far to move the insertion point.
@ -1099,7 +1232,8 @@ and layout is left-to-right */
return; return;
} }
[self _move: GSInsertionPointMoveDown [self _moveFrom: cIndex
direction: GSInsertionPointMoveDown
distance: scrollDelta distance: scrollDelta
select: flag]; select: flag];
} }
@ -1125,7 +1259,17 @@ and layout is left-to-right */
float scrollDelta; float scrollDelta;
float oldOriginY; float oldOriginY;
float newOriginY; float newOriginY;
unsigned int cIndex;
if (flag)
{
cIndex = [self _movementOrigin];
}
else
{
cIndex = [self _characterIndexForSelectedRange:[self selectedRange]
direction: GSInsertionPointMoveUp];
}
/* /*
* Scroll; also determine how far to move the insertion point. * Scroll; also determine how far to move the insertion point.
*/ */
@ -1140,7 +1284,8 @@ and layout is left-to-right */
return; return;
} }
[self _move: GSInsertionPointMoveUp [self _moveFrom: cIndex
direction: GSInsertionPointMoveUp
distance: -scrollDelta distance: -scrollDelta
select: flag]; select: flag];
} }