Allow almost anything as a key equivalent unless a text field is the first responder.

After testing in Cocoa, even unexpected keys such as tab can be used when a text field isn't selected. Some keys such as the arrow keys and escape act like key equivalents even with a text field active.
This commit is contained in:
Alexander Ljungberg committed 2011-11-10 00:52:38 +00:00
1 parent 00485dba89
commit 8f90dbce99
2 files changed
+16 -11

No files matched your search

+6 -9
View File
@@ -571,10 +571,12 @@ var _CPEventPeriodicEventPeriod = 0,
if (_modifierFlags & (CPCommandKeyMask | CPControlKeyMask))
return YES;
// Cocoa does not consider space, backspace, or escape a key equivalent
// if the first responder is a text field (presumably a subclass of NSText).
// Cocoa allows almost any key as a key equivalent unless the first responder is a
// text field (presumably a subclass of NSText.)
var firstResponderIsText = [[_window firstResponder] isKindOfClass:[CPTextField class]];
// Some keys are accepted as key equivalents even if the first responder is a text
// field.
for (var i = 0; i < characterCount; i++)
{
var c = _characters.charAt(i);
@@ -583,18 +585,13 @@ var _CPEventPeriodicEventPeriod = 0,
c === CPEnterCharacter ||
c === CPNewlineCharacter ||
c === CPCarriageReturnCharacter ||
c === CPEscapeFunctionKey ||
(!firstResponderIsText &&
(c === CPSpaceFunctionKey ||
c === CPDeleteCharacter ||
c === CPBackspaceCharacter)))
c === CPEscapeFunctionKey)
{
return YES;
}
}
// FIXME: More cases?
return NO;
return !firstResponderIsText;
}
/*!
+10 -2
View File
@@ -60,7 +60,6 @@
[contentView addSubview:button];
}
var label = [[CPTextField alloc] initWithFrame:CGRectMakeZero()];
[label setStringValue:@"Press the appropriate key on the keyboard for each button and verify that it reacts."];
[label setFont:[CPFont boldSystemFontOfSize:14.0]];
@@ -86,7 +85,7 @@
["down arrow", CPDownArrowFunctionKey],
["home", CPHomeFunctionKey],
["end", CPEndFunctionKey]
];
];
for (var i = 0, buttonsWide = 6, yOffset = 0; i < functionKeysToTest.length; i++)
{
@@ -102,6 +101,15 @@
[contentView addSubview:button];
}
var label2 = [[CPTextField alloc] initWithFrame:CGRectMake(10, 140 + yOffset + 24, 100, 24)];
[label2 setStringValue:@"If a text field is the first responder, some key equivalents are ignored."];
[label2 sizeToFit];
[contentView addSubview:label2];
var textField = [CPTextField textFieldWithStringValue:"" placeholder:"" width:100];
[textField setFrameOrigin:CGPointMake(10, CGRectGetMaxY([label2 frame]) + 10)];
[contentView addSubview:textField];
[theWindow orderFront:self];
}