Fix implementation of NSTextView's transpose action to really match

the implementation of Emacs' transpose command.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@27366 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Wolfgang Lux 2008-12-21 11:40:58 +00:00
parent 8279ffddbb
commit ad13684362
2 changed files with 27 additions and 13 deletions

View file

@ -8,6 +8,9 @@
* Source/NSTextView_actions.m (-centerSelectionInVisibleArea):
Replace the provisional implementation by a correct one.
* Source/NSTextView_actions.m (-transpose): Fix implementation to
really match the implementation of Emacs' transpose command.
2008-12-20 22:13-EST Gregory John Casamento <greg_casamento@yahoo.com>
* Source/GSNibLoading.m: Read objects/accessibility and oids

View file

@ -1381,15 +1381,15 @@ and layout is left-to-right */
}
/* The following method is bound to 'Control-t', and must work like
* pressing 'Control-t' inside Emacs. For example, say that I type
* 'Nicoal' in a NSTextView. Then, I press 'Control-t'. This should
* swap the last two characters which were inserted, thus swapping the
* 'a' and the 'l', and changing the text to read 'Nicola'. */
/*
TODO: description incorrect. should swap characters on either side of the
insertion point. (see also: miswart)
*/
/* The following method is bound to 'Control-t', and works exactly like
* pressing 'Control-t' inside Emacs, i.e., in general it swaps the
* character immediately before and after the insertion point and moves
* the insertion point forward by one character. If, however, the
* insertion point is at the end of a line, it swaps the two characters
* before the insertion point and does not move the insertion point.
* Note that Mac OS X does not implement the special case at the end
* of a line, but I consider Emacs' behavior more useful.
*/
- (void) transpose: (id)sender
{
NSRange range = [self selectedRange];
@ -1397,16 +1397,26 @@ insertion point. (see also: miswart)
NSString *replacementString;
unichar chars[2];
/* Do nothing if we are at beginning of text. */
if (range.location < 2)
/* Do nothing if the selection is not empty or if we are at the
* beginning of text. */
if (range.length > 0 || range.location < 1)
{
return;
}
range = NSMakeRange(range.location - 2, 2);
range = NSMakeRange(range.location - 1, 2);
/* Eventually adjust the range if we are at the end of a line. */
string = [_textStorage string];
if (range.location + 1 == [string length]
|| [string characterAtIndex: range.location + 1] == '\n')
{
if (range.location == 0)
return;
range.location -= 1;
}
/* Get the two chars and swap them. */
string = [_textStorage string];
chars[1] = [string characterAtIndex: range.location];
chars[0] = [string characterAtIndex: (range.location + 1)];
@ -1418,6 +1428,7 @@ insertion point. (see also: miswart)
{
[self replaceCharactersInRange: range
withString: replacementString];
[self setSelectedRange: NSMakeRange(range.location + 2, 0)];
[self didChangeText];
}
}