From 3a3667298256accac87fdbc01af65b4d0220090e Mon Sep 17 00:00:00 2001 From: Bjorn Winckler Date: Mon, 19 Nov 2007 21:20:56 +0100 Subject: [PATCH] Improved support for Ctrl-mappings Ctrl-letter keys are passed directly to the input buffer so that the backend can separate e.g. and . --- src/MacVim/MMBackend.m | 2 +- src/MacVim/MMTextView.m | 22 ++++++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/MacVim/MMBackend.m b/src/MacVim/MMBackend.m index d273777027..184d980ff6 100644 --- a/src/MacVim/MMBackend.m +++ b/src/MacVim/MMBackend.m @@ -1722,7 +1722,7 @@ enum { // 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) - || 0x9 == c || 0xd == c) ) { + || 0x9 == c || 0xd == c || ESC == c) ) { mods &= ~MOD_MASK_SHIFT; mods &= ~MOD_MASK_CTRL; //NSLog(@"clear shift ctrl"); diff --git a/src/MacVim/MMTextView.m b/src/MacVim/MMTextView.m index bda16d6ef2..36e623da07 100644 --- a/src/MacVim/MMTextView.m +++ b/src/MacVim/MMTextView.m @@ -177,17 +177,27 @@ static NSString *MMKeypadEnterString = @"KA"; - (void)keyDown:(NSEvent *)event { //NSLog(@"%s %@", _cmd, event); - // HACK! If a modifier is held, don't pass the event along to + // HACK! If control modifier is held, don't pass the event along to // interpretKeyEvents: since some keys are bound to multiple commands which // means doCommandBySelector: is called several times. // // TODO: Figure out a way to disable Cocoa key bindings entirely, without // affecting input management. - - if ([event modifierFlags] & NSControlKeyMask) - [self dispatchKeyEvent:event]; - else + if ([event modifierFlags] & NSControlKeyMask) { + NSString *unmod = [event charactersIgnoringModifiers]; + if ([unmod length] == 1 && [unmod characterAtIndex:0] <= 0x7f + && [unmod characterAtIndex:0] >= 0x60) { + // HACK! Send Ctrl-letter keys (and C-@, C-[, C-\, C-], C-^, C-_) + // as normal text to be added to the Vim input buffer. This must + // be done in order for the backend to be able to separate e.g. + // Ctrl-i and Ctrl-tab. + [self insertText:[event characters]]; + } else { + [self dispatchKeyEvent:event]; + } + } else { [super keyDown:event]; + } } - (void)insertText:(id)string @@ -310,7 +320,7 @@ static NSString *MMKeypadEnterString = @"KA"; // HACK! On Leopard Ctrl-key events end up here instead of keyDown:. if (flags & NSControlKeyMask) { - [self dispatchKeyEvent:event]; + [self keyDown:event]; return YES; }