diff --git a/src/MacVim/MMBackend.m b/src/MacVim/MMBackend.m index 4960e7bac8..b2e41fd3e1 100644 --- a/src/MacVim/MMBackend.m +++ b/src/MacVim/MMBackend.m @@ -1954,8 +1954,19 @@ static void netbeansReadCallback(CFSocketRef s, if (mods & MOD_MASK_CMD) { // NOTE: For normal input (non-special, 'macmeta' off) the modifier // flags are already included in the key event. However, the Cmd key - // flag is special and must always be added manually. The frontend is - // responsible for clearing unnecessary flags when Cmd is held. + // flag is special and must always be added manually. + // The Shift flag is already included in the key when the Command + // key is held. The same goes for Alt, unless Ctrl is held or + // 'macmeta' is set. It is important that these flags are cleared + // _after_ special keys have been handled, since they should never be + // cleared for special keys. + mods &= ~MOD_MASK_SHIFT; + if (!(mods & MOD_MASK_CTRL)) { + BOOL mmta = curbuf ? curbuf->b_p_mmta : YES; + if (!mmta) + mods &= ~MOD_MASK_ALT; + } + ASLogDebug(@"add mods=%#x", mods); char_u modChars[3] = { CSI, KS_MODIFIER, mods }; add_to_input_buf(modChars, 3); diff --git a/src/MacVim/MMTextViewHelper.m b/src/MacVim/MMTextViewHelper.m index 6f29bcb3b3..31d8665cb8 100644 --- a/src/MacVim/MMTextViewHelper.m +++ b/src/MacVim/MMTextViewHelper.m @@ -162,8 +162,8 @@ KeyboardInputSourcesEqual(TISInputSourceRef a, TISInputSourceRef b) // HACK! When Command is held we have to more or less guess whether // we should use characters or charactersIgnoringModifiers. The // following heuristic seems to work but it may have to change. - // Note that the Shift and Alt flags may be cleared before passing - // the event on to Vim (see doKeyDown:). + // Note that the Shift and Alt flags may also need to be cleared + // (see doKeyDown:keyCode:modifiers: in MMBackend). if ((flags & NSShiftKeyMask && !(flags & NSAlternateKeyMask)) || flags & NSControlKeyMask) string = unmod; @@ -897,18 +897,6 @@ KeyboardInputSourcesEqual(TISInputSourceRef a, TISInputSourceRef b) unsigned keyCode = [currentEvent keyCode]; unsigned flags = [currentEvent modifierFlags]; - if (flags & NSCommandKeyMask) { - // The Shift flag is already included in the key when the Command key - // is held. The same goes for Alt, unless Ctrl is held or 'macmeta' is - // set. - flags &= ~NSShiftKeyMask; - if (!(flags & NSControlKeyMask)) { - id mmta = [[[self vimController] vimState] objectForKey:@"p_mmta"]; - if (![mmta boolValue]) - flags &= ~NSAlternateKeyMask; - } - } - // The low 16 bits are not used for modifier flags by NSEvent. Use // these bits for custom flags. flags &= NSDeviceIndependentModifierFlagsMask;