mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-10-07 01:18:02 +00:00
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:
1 parent
00485dba89
commit
8f90dbce99
2 files changed
+16
-11
No files matched your search
+6
-9
@@ -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;
|
||||
}
|
||||
|
||||
/*!
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user