@@ -170,21 +170,34 @@ - (void)keyDown:(NSEvent *)event
170170 && [unmod length ] == 1
171171 && ([unmod characterAtIndex: 0 ] == ' 6' ||
172172 [unmod characterAtIndex: 0 ] == ' ^' )) {
173- // HACK! interpretKeyEvents: does not call doCommandBySelector:
173+ // HACK! interpretKeyEvents: does not call doCommandBySelector:
174174 // with Ctrl-6 or Ctrl-^ when IM is active.
175175 [self doKeyDown: @" \x1e " ];
176176 string = nil ;
177177 } else {
178- // When using JapaneseIM with "Windows-like shortcuts" turned on,
178+ // HACK! When using JapaneseIM with "Windows-like shortcuts" turned on,
179179 // interpretKeyEvents: does not call doCommandBySelector: with Ctrl-O
180180 // and Ctrl-U (why?), so we cannot handle them at all.
181- // As a workaround, we do not call interpretKeyEvents: when no marked
182- // text and with only control-modifier.
183- if ([self hasMarkedText ] || (!modControl || modCommand || modOption)) {
184- // HACK! interpretKeyEvents: may call insertText: or
185- // doCommandBySelector:, or it may swallow the key (most likely the
186- // current input method used it). In the first two cases we have to
187- // manually set the below flag to NO if the key wasn't handled.
181+ // As a workaround, we do not call interpretKeyEvents: with Ctrl-O or
182+ // Ctrl-U when there is no marked text.
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.
188201 interpretKeyEventsSwallowedKey = YES ;
189202 [textView interpretKeyEvents: [NSArray arrayWithObject: event]];
190203 if (interpretKeyEventsSwallowedKey)
0 commit comments