From 85a4f20e0ce7a73edcf4cf9d6393381cccc2db24 Mon Sep 17 00:00:00 2001 From: Joe Wreschnig Date: Sun, 10 Mar 2013 22:52:01 +0100 Subject: [PATCH] Ignore and stop listening if the key event has either Command or Alt modifier bits set, so e.g. Cmd-W doesn't reset the key. --- Classes/NJKeyInputField.m | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/Classes/NJKeyInputField.m b/Classes/NJKeyInputField.m index c9b2f4d..814fdfe 100644 --- a/Classes/NJKeyInputField.m +++ b/Classes/NJKeyInputField.m @@ -173,25 +173,21 @@ CGKeyCode NJKeyInputFieldEmpty = 0xFFFF; self.stringValue = [NJKeyInputField stringForKeyCode:keyCode]; } -- (void)keyDown:(NSEvent *)theEvent { - if (!theEvent.isARepeat) { - if ((theEvent.modifierFlags & NSAlternateKeyMask) - && theEvent.keyCode == 0x33) { - // Allow Alt+Backspace to clear the field. +- (void)keyDown:(NSEvent *)event { + static const NSUInteger IGNORE = NSAlternateKeyMask | NSCommandKeyMask; + if (!event.isARepeat) { + if ((event.modifierFlags & IGNORE) && event.keyCode == 0x33) { + // Allow Alt/Command+Backspace to clear the field. self.keyCode = NJKeyInputFieldEmpty; [self.keyDelegate keyInputFieldDidClear:self]; - } else if ((theEvent.modifierFlags & NSAlternateKeyMask) - && theEvent.keyCode == 0x35) { - // Allow Alt+Escape to cancel. - ; - } else { - self.keyCode = theEvent.keyCode; - [self.keyDelegate keyInputField:self didChangeKey:_keyCode]; + } else if (!(event.modifierFlags & IGNORE)) { + self.keyCode = event.keyCode; + [self.keyDelegate keyInputField:self didChangeKey:self.keyCode]; } [self resignIfFirstResponder]; } } - + - (void)mouseDown:(NSEvent *)theEvent { if (self.window.firstResponder == self) [self.window makeFirstResponder:nil]; -- 2.30.2