mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-26 12:01:14 +00:00
Implemented transpose: (which is bound to Control-t)
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@12394 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
55ca3c3ffd
commit
58b76b645a
1 changed files with 37 additions and 0 deletions
|
@ -2736,6 +2736,43 @@ afterString in order over charRange. */
|
|||
}
|
||||
}
|
||||
|
||||
/* 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'. */
|
||||
- (void) transpose: (id)sender
|
||||
{
|
||||
NSRange range;
|
||||
NSString *string;
|
||||
NSString *replacementString;
|
||||
unichar chars[2];
|
||||
unichar tmp;
|
||||
|
||||
/* Do nothing if we are at beginning of text. */
|
||||
if (_selected_range.location < 2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
range = NSMakeRange (_selected_range.location - 2, 2);
|
||||
|
||||
/* Get the two chars. */
|
||||
string = [_textStorage string];
|
||||
chars[0] = [string characterAtIndex: (_selected_range.location - 2)];
|
||||
chars[1] = [string characterAtIndex: (_selected_range.location - 1)];
|
||||
|
||||
/* Swap them. */
|
||||
tmp = chars[0];
|
||||
chars[0] = chars[1];
|
||||
chars[1] = tmp;
|
||||
|
||||
/* Replace the original chars with the swapped ones. */
|
||||
replacementString = [NSString stringWithCharacters: chars length: 2];
|
||||
[self replaceCharactersInRange: range withString: replacementString];
|
||||
}
|
||||
|
||||
|
||||
- (BOOL) acceptsFirstResponder
|
||||
{
|
||||
if (_tf.is_selectable)
|
||||
|
|
Loading…
Reference in a new issue