From bc28f07b5ebd9c84f59a9b672f178ac990540563 Mon Sep 17 00:00:00 2001 From: Bjorn Winckler Date: Wed, 23 Jan 2008 19:39:13 +0100 Subject: [PATCH] and not triggered twice The default Cocoa key bindings map these key presses to two commands which led them to be triggered twice. Avoid this by passing Alt+Function key presses straight to Vim instead of to interpretKeyEvents:. --- src/MacVim/MMAtsuiTextView.m | 9 +++++++-- src/MacVim/MMTextView.m | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/MacVim/MMAtsuiTextView.m b/src/MacVim/MMAtsuiTextView.m index 9ea9fb5b93..3e4b73a667 100644 --- a/src/MacVim/MMAtsuiTextView.m +++ b/src/MacVim/MMAtsuiTextView.m @@ -261,11 +261,16 @@ enum { //NSLog(@"%s %@", _cmd, event); // 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. + // means doCommandBySelector: is called several times. Do the same for + // Alt+Function key presses (Alt+Up and Alt+Down are bound to two + // commands). This hack may break input management, but unless we can + // figure out a way to disable key bindings there seems little else to do. // // TODO: Figure out a way to disable Cocoa key bindings entirely, without // affecting input management. - if ([event modifierFlags] & NSControlKeyMask) { + int flags = [event modifierFlags]; + if ((flags & NSControlKeyMask) || + ((flags & NSAlternateKeyMask) && (flags & NSFunctionKeyMask))) { NSString *unmod = [event charactersIgnoringModifiers]; if ([unmod length] == 1 && [unmod characterAtIndex:0] <= 0x7f && [unmod characterAtIndex:0] >= 0x60) { diff --git a/src/MacVim/MMTextView.m b/src/MacVim/MMTextView.m index b1e7148c95..3d7df765c0 100644 --- a/src/MacVim/MMTextView.m +++ b/src/MacVim/MMTextView.m @@ -487,11 +487,16 @@ enum { //NSLog(@"%s %@", _cmd, event); // 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. + // means doCommandBySelector: is called several times. Do the same for + // Alt+Function key presses (Alt+Up and Alt+Down are bound to two + // commands). This hack may break input management, but unless we can + // figure out a way to disable key bindings there seems little else to do. // // TODO: Figure out a way to disable Cocoa key bindings entirely, without // affecting input management. - if ([event modifierFlags] & NSControlKeyMask) { + int flags = [event modifierFlags]; + if ((flags & NSControlKeyMask) || + ((flags & NSAlternateKeyMask) && (flags & NSFunctionKeyMask))) { NSString *unmod = [event charactersIgnoringModifiers]; if ([unmod length] == 1 && [unmod characterAtIndex:0] <= 0x7f && [unmod characterAtIndex:0] >= 0x60) {