From a74e1fe57dd4b8300c3565133aaad397b7ec50ea Mon Sep 17 00:00:00 2001 From: Bjorn Winckler Date: Sat, 22 Sep 2007 19:05:41 +0000 Subject: [PATCH] Can now map to Tab with modifiers git-svn-id: http://macvim.googlecode.com/svn/trunk@260 96c4425d-ca35-0410-94e5-3396d5c13a8f --- MMBackend.m | 38 ++++++++++++++++++++++++++++++++------ MMTextView.m | 24 ++++++++++++++---------- SpecialKeys.plist | 2 -- 3 files changed, 46 insertions(+), 18 deletions(-) diff --git a/MMBackend.m b/MMBackend.m index 07b6356d9b..9459fda341 100644 --- a/MMBackend.m +++ b/MMBackend.m @@ -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: + // - is added to the input buffer as is + // - is translated to, {CSI,'k','B'} (i.e. 'Back-tab') + // - should be 0x80|TAB but this is not valid utf-8 so it needs + // to be converted to utf-8 + // - is translated to with ALT modifier + // - is reserved by Mac OS X + // - 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"); diff --git a/MMTextView.m b/MMTextView.m index dc92394a6e..57cfc91294 100644 --- a/MMTextView.m +++ b/MMTextView.m @@ -180,16 +180,19 @@ static NSString *MMKeypadEnterString = @"KA"; NSEvent *event = [NSApp currentEvent]; - // HACK! In order to be able to bind to etc. we have to watch - // for when space was pressed. + // HACK! In order to be able to bind to , , 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]; + + // 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 diff --git a/SpecialKeys.plist b/SpecialKeys.plist index 180302d040..be1f7784c4 100644 --- a/SpecialKeys.plist +++ b/SpecialKeys.plist @@ -4,8 +4,6 @@ KA KA - kB - kB  kb