Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 23 additions & 16 deletions src/MacVim/MMTextViewHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -151,20 +151,22 @@ - (void)keyDown:(NSEvent *)event
id mmta = [[[self vimController] vimState] objectForKey:@"p_mmta"];
NSString *string = [event characters];
NSString *unmod = [event charactersIgnoringModifiers];
BOOL modCommand = (flags & NSEventModifierFlagCommand) ? YES : NO;
BOOL modControl = (flags & NSEventModifierFlagControl) ? YES : NO;
BOOL modOption = (flags & NSEventModifierFlagOption) ? YES : NO;
BOOL modShift = (flags & NSEventModifierFlagShift) ? YES : NO;

// Alt key presses should not be interpreted if the 'macmeta' option is
// set. We still have to call interpretKeyEvents: for keys
// like Enter, Esc, etc. to work as usual so only skip interpretation for
// ASCII chars in the range after space (0x20) and before backspace (0x7f).
// Note that this implies that 'mmta' (if enabled) breaks input methods
// when the Alt key is held.
if ((flags & NSEventModifierFlagOption)
&& [mmta boolValue] && [unmod length] == 1
if (modOption && [mmta boolValue] && [unmod length] == 1
&& [unmod characterAtIndex:0] > 0x20) {
ASLogDebug(@"MACMETA key, don't interpret it");
string = unmod;
} else if (imState && (flags & NSEventModifierFlagControl)
&& !(flags & (NSEventModifierFlagOption|NSEventModifierFlagCommand))
} else if (imState && (modControl && !modCommand && !modOption)
&& [unmod length] == 1
&& ([unmod characterAtIndex:0] == '6' ||
[unmod characterAtIndex:0] == '^')) {
Expand All @@ -173,23 +175,28 @@ - (void)keyDown:(NSEvent *)event
[self doKeyDown:@"\x1e"];
string = nil;
} else {
// HACK! interpretKeyEvents: may call insertText: or
// doCommandBySelector:, or it may swallow the key (most likely the
// current input method used it). In the first two cases we have to
// manually set the below flag to NO if the key wasn't handled.
interpretKeyEventsSwallowedKey = YES;
[textView interpretKeyEvents:[NSArray arrayWithObject:event]];
if (interpretKeyEventsSwallowedKey)
string = nil;
else if (flags & NSEventModifierFlagCommand) {
// When using JapaneseIM with "Windows-like shortcuts" turned on,
// interpretKeyEvents: does not call doCommandBySelector: with Ctrl-O
// and Ctrl-U (why?), so we cannot handle them at all.
// As a workaround, we do not call interpretKeyEvents: when no marked
// text and with only control-modifier.
if ([self hasMarkedText] || (!modControl || modCommand || modOption)) {
// HACK! interpretKeyEvents: may call insertText: or
// doCommandBySelector:, or it may swallow the key (most likely the
// current input method used it). In the first two cases we have to
// manually set the below flag to NO if the key wasn't handled.
interpretKeyEventsSwallowedKey = YES;
[textView interpretKeyEvents:[NSArray arrayWithObject:event]];
if (interpretKeyEventsSwallowedKey)
string = nil;
}
if (string && modCommand) {
// 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 also need to be cleared
// (see doKeyDown:keyCode:modifiers: in MMBackend).
if ((flags & NSEventModifierFlagShift
&& !(flags & NSEventModifierFlagOption))
|| flags & NSEventModifierFlagControl)
if ((modShift && !modOption) || modControl)
string = unmod;
}
}
Expand Down