Can now map to Tab with modifiers

git-svn-id: http://macvim.googlecode.com/svn/trunk@260 96c4425d-ca35-0410-94e5-3396d5c13a8f
This commit is contained in:
Bjorn Winckler
2007-09-22 19:05:41 +00:00
parent c234e0b8dd
commit a74e1fe57d
3 changed files with 46 additions and 18 deletions
+32 -6
View File
@@ -1670,8 +1670,8 @@ enum {
{
char_u special[3];
char_u modChars[3];
char_u *chars = 0;
int length = 0;
char_u *chars = (char_u*)[key UTF8String];
int length = [key lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
// Special keys (arrow keys, function keys, etc.) are stored in a plist so
// that new keys can easily be added.
@@ -1692,9 +1692,34 @@ enum {
chars = special;
length = 3;
} else if ([key length] > 0) {
chars = (char_u*)[key UTF8String];
length = [key lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
} else if (1 == length && TAB == chars[0]) {
// Tab is a trouble child:
// - <Tab> is added to the input buffer as is
// - <S-Tab> is translated to, {CSI,'k','B'} (i.e. 'Back-tab')
// - <M-Tab> should be 0x80|TAB but this is not valid utf-8 so it needs
// to be converted to utf-8
// - <S-M-Tab> is translated to <S-Tab> with ALT modifier
// - <C-Tab> is reserved by Mac OS X
// - <D-Tab> is reserved by Mac OS X
chars = special;
special[0] = TAB;
length = 1;
if (mods & MOD_MASK_SHIFT) {
mods &= ~MOD_MASK_SHIFT;
special[0] = CSI;
special[1] = K_SECOND(K_S_TAB);
special[2] = K_THIRD(K_S_TAB);
length = 3;
} else if (mods & MOD_MASK_ALT) {
int mtab = 0x80 | TAB;
// Convert to utf-8
special[0] = (mtab >> 6) + 0xc0;
special[1] = mtab & 0xbf;
length = 2;
mods &= ~MOD_MASK_ALT;
}
} else if (length > 0) {
unichar c = [key characterAtIndex:0];
//NSLog(@"non-special: %@ (hex=%x, mods=%d)", key,
@@ -1710,7 +1735,8 @@ enum {
// cleared since they are already added to the key by the AppKit.
// Unfortunately, the only way to deal with when to clear the modifiers
// or not seems to be to have hard-wired rules like this.
if ( !((' ' == c) || (0xa0 == c) || (mods & MOD_MASK_CMD)) ) {
if ( !((' ' == c) || (0xa0 == c) || (mods & MOD_MASK_CMD)
|| 0x9 == c) ) {
mods &= ~MOD_MASK_SHIFT;
mods &= ~MOD_MASK_CTRL;
//NSLog(@"clear shift ctrl");
+14 -10
View File
@@ -180,16 +180,19 @@ static NSString *MMKeypadEnterString = @"KA";
NSEvent *event = [NSApp currentEvent];
// HACK! In order to be able to bind to <S-Space> etc. we have to watch
// for when space was pressed.
// HACK! In order to be able to bind to <S-Space>, <S-M-Tab>, etc. we have
// to watch for them here.
if ([event type] == NSKeyDown
&& [[event charactersIgnoringModifiers] length] > 0
&& [[event charactersIgnoringModifiers] characterAtIndex:0] == ' '
&& [event modifierFlags]
& (NSShiftKeyMask|NSControlKeyMask|NSAlternateKeyMask))
{
[self dispatchKeyEvent:event];
return;
& (NSShiftKeyMask|NSControlKeyMask|NSAlternateKeyMask)) {
unichar c = [[event charactersIgnoringModifiers] characterAtIndex:0];
// <S-M-Tab> translates to 0x19
if (' ' == c || 0x19 == c) {
[self dispatchKeyEvent:event];
return;
}
}
// TODO: Support 'mousehide' (check p_mh)
@@ -835,6 +838,7 @@ static NSString *MMKeypadEnterString = @"KA";
unichar imc = [unmodchars characterAtIndex:0];
int len = 0;
const char *bytes = 0;
int mods = [event modifierFlags];
//NSLog(@"%s chars[0]=0x%x unmodchars[0]=0x%x (chars=%@ unmodchars=%@)",
// _cmd, c, imc, chars, unmodchars);
@@ -856,14 +860,14 @@ static NSString *MMKeypadEnterString = @"KA";
} else if (c == 0x19 && imc == 0x19) {
// HACK! AppKit turns back tab into Ctrl-Y, so we need to handle it
// separately (else Ctrl-Y doesn't work).
static char back_tab[2] = { 'k', 'B' };
len = 2; bytes = back_tab;
static char tab = 0x9;
len = 1; bytes = &tab; mods |= NSShiftKeyMask;
} else {
len = [chars lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
bytes = [chars UTF8String];
}
[self sendKeyDown:bytes length:len modifiers:[event modifierFlags]];
[self sendKeyDown:bytes length:len modifiers:mods];
}
- (MMVimController *)vimController
-2
View File
@@ -4,8 +4,6 @@
<dict>
<key>KA</key>
<string>KA</string>
<key>kB</key>
<string>kB</string>
<key></key>
<string>kb</string>
<key></key>