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
31 changes: 22 additions & 9 deletions src/MacVim/MMTextViewHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -170,21 +170,34 @@ - (void)keyDown:(NSEvent *)event
&& [unmod length] == 1
&& ([unmod characterAtIndex:0] == '6' ||
[unmod characterAtIndex:0] == '^')) {
// HACK! interpretKeyEvents: does not call doCommandBySelector:
// HACK! interpretKeyEvents: does not call doCommandBySelector:
// with Ctrl-6 or Ctrl-^ when IM is active.
[self doKeyDown:@"\x1e"];
string = nil;
} else {
// When using JapaneseIM with "Windows-like shortcuts" turned on,
// HACK! 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.
// As a workaround, we do not call interpretKeyEvents: with Ctrl-O or
// Ctrl-U when there is no marked text.
BOOL isJapaneseIME = [[[NSTextInputContext currentInputContext]
selectedKeyboardInputSource]
hasPrefix:@"com.apple.inputmethod.Kotoeri"];
BOOL isJapaneseIMCtrlUO = (isJapaneseIME
&& (modControl && !modCommand && !modOption)
&& ([unmod characterAtIndex:0] == 'o' ||
[unmod characterAtIndex:0] == 'u'));

if ([self hasMarkedText] || !isJapaneseIMCtrlUO) {
// 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, which allows us to
// manually send the key down event.
//
// doCommandBySelector: will also perform misc translations such as
// Ctrl-6 -> Ctrl-^, so this should not be skipped unless there are
// special cases like the Japanese IME Ctrl-U issue.
interpretKeyEventsSwallowedKey = YES;
[textView interpretKeyEvents:[NSArray arrayWithObject:event]];
if (interpretKeyEventsSwallowedKey)
Expand Down