Skip to content

Commit d8606ce

Browse files
committed
Refactor Ctrl-6 fix to be clearer and only trigger under Japanese IME
Only limiting this condition to be under Japanese IME helps prevents unintended effects on other IMEs as well, as this bug is only known to happen under Japanese IME with Windows shortcuts. Also update comments to be clear that most of the time you do want to go through the interpretKeyEvents: path.
1 parent 7c6b2b0 commit d8606ce

1 file changed

Lines changed: 18 additions & 8 deletions

File tree

src/MacVim/MMTextViewHelper.m

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -180,14 +180,24 @@ - (void)keyDown:(NSEvent *)event
180180
// and Ctrl-U (why?), so we cannot handle them at all.
181181
// As a workaround, we do not call interpretKeyEvents: with Ctrl-O or
182182
// Ctrl-U when there is no marked text.
183-
if ([self hasMarkedText]
184-
|| !((modControl && !modCommand && !modOption)
185-
&& ([unmod characterAtIndex:0] == 'o' ||
186-
[unmod characterAtIndex:0] == 'u'))) {
187-
// HACK! interpretKeyEvents: may call insertText: or
188-
// doCommandBySelector:, or it may swallow the key (most likely the
189-
// current input method used it). In the first two cases we have to
190-
// manually set the below flag to NO if the key wasn't handled.
183+
BOOL isJapaneseIME = [[[NSTextInputContext currentInputContext]
184+
selectedKeyboardInputSource]
185+
hasPrefix:@"com.apple.inputmethod.Kotoeri"];
186+
BOOL isJapaneseIMCtrlUO = (isJapaneseIME
187+
&& (modControl && !modCommand && !modOption)
188+
&& ([unmod characterAtIndex:0] == 'o' ||
189+
[unmod characterAtIndex:0] == 'u'));
190+
191+
if ([self hasMarkedText] || !isJapaneseIMCtrlUO) {
192+
// interpretKeyEvents: may call insertText: or doCommandBySelector:,
193+
// or it may swallow the key (most likely the current input method
194+
// used it). In the first two cases we have to manually set the
195+
// below flag to NO if the key wasn't handled, which allows us to
196+
// manually send the key down event.
197+
//
198+
// doCommandBySelector: will also perform misc translations such as
199+
// Ctrl-6 -> Ctrl-^, so this should not be skipped unless there are
200+
// special cases like the Japanese IME Ctrl-U issue.
191201
interpretKeyEventsSwallowedKey = YES;
192202
[textView interpretKeyEvents:[NSArray arrayWithObject:event]];
193203
if (interpretKeyEventsSwallowedKey)

0 commit comments

Comments
 (0)