Skip to content

Commit 221664c

Browse files
committed
Add the condition for calling interpretKeyEvents
1 parent 3f1f9b0 commit 221664c

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

src/MacVim/MMTextViewHelper.m

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -151,20 +151,22 @@ - (void)keyDown:(NSEvent *)event
151151
id mmta = [[[self vimController] vimState] objectForKey:@"p_mmta"];
152152
NSString *string = [event characters];
153153
NSString *unmod = [event charactersIgnoringModifiers];
154+
BOOL modCommand = (flags & NSEventModifierFlagCommand) ? YES : NO;
155+
BOOL modControl = (flags & NSEventModifierFlagControl) ? YES : NO;
156+
BOOL modOption = (flags & NSEventModifierFlagOption) ? YES : NO;
157+
BOOL modShift = (flags & NSEventModifierFlagShift) ? YES : NO;
154158

155159
// Alt key presses should not be interpreted if the 'macmeta' option is
156160
// set. We still have to call interpretKeyEvents: for keys
157161
// like Enter, Esc, etc. to work as usual so only skip interpretation for
158162
// ASCII chars in the range after space (0x20) and before backspace (0x7f).
159163
// Note that this implies that 'mmta' (if enabled) breaks input methods
160164
// when the Alt key is held.
161-
if ((flags & NSEventModifierFlagOption)
162-
&& [mmta boolValue] && [unmod length] == 1
165+
if (modOption && [mmta boolValue] && [unmod length] == 1
163166
&& [unmod characterAtIndex:0] > 0x20) {
164167
ASLogDebug(@"MACMETA key, don't interpret it");
165168
string = unmod;
166-
} else if (imState && (flags & NSEventModifierFlagControl)
167-
&& !(flags & (NSEventModifierFlagOption|NSEventModifierFlagCommand))
169+
} else if (imState && (modControl && !modCommand && !modOption)
168170
&& [unmod length] == 1
169171
&& ([unmod characterAtIndex:0] == '6' ||
170172
[unmod characterAtIndex:0] == '^')) {
@@ -173,23 +175,28 @@ - (void)keyDown:(NSEvent *)event
173175
[self doKeyDown:@"\x1e"];
174176
string = nil;
175177
} else {
176-
// HACK! interpretKeyEvents: may call insertText: or
177-
// doCommandBySelector:, or it may swallow the key (most likely the
178-
// current input method used it). In the first two cases we have to
179-
// manually set the below flag to NO if the key wasn't handled.
180-
interpretKeyEventsSwallowedKey = YES;
181-
[textView interpretKeyEvents:[NSArray arrayWithObject:event]];
182-
if (interpretKeyEventsSwallowedKey)
183-
string = nil;
184-
else if (flags & NSEventModifierFlagCommand) {
178+
// When using JapaneseIM with "Windows-like shortcuts" turned on,
179+
// interpretKeyEvents: does not call doCommandBySelector: with Ctrl-O
180+
// 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.
188+
interpretKeyEventsSwallowedKey = YES;
189+
[textView interpretKeyEvents:[NSArray arrayWithObject:event]];
190+
if (interpretKeyEventsSwallowedKey)
191+
string = nil;
192+
}
193+
if (string && modCommand) {
185194
// HACK! When Command is held we have to more or less guess whether
186195
// we should use characters or charactersIgnoringModifiers. The
187196
// following heuristic seems to work but it may have to change.
188197
// Note that the Shift and Alt flags may also need to be cleared
189198
// (see doKeyDown:keyCode:modifiers: in MMBackend).
190-
if ((flags & NSEventModifierFlagShift
191-
&& !(flags & NSEventModifierFlagOption))
192-
|| flags & NSEventModifierFlagControl)
199+
if ((modShift && !modOption) || modControl)
193200
string = unmod;
194201
}
195202
}

0 commit comments

Comments
 (0)