mirror of
https://github.com/macvim-dev/macvim.git
synced 2026-06-11 15:37:29 +02:00
Merge pull request #742 from ichizok/fix/windows-like-shortcuts
<C-U> and <C-O> don't work when using Japanese IM with "Windows-like shortcuts" turned on
This commit is contained in:
@@ -151,6 +151,10 @@ KeyboardInputSourcesEqual(TISInputSourceRef a, TISInputSourceRef b)
|
||||
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
|
||||
@@ -158,13 +162,11 @@ KeyboardInputSourcesEqual(TISInputSourceRef a, TISInputSourceRef b)
|
||||
// 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] == '^')) {
|
||||
@@ -173,23 +175,28 @@ KeyboardInputSourcesEqual(TISInputSourceRef a, TISInputSourceRef b)
|
||||
[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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user