Unverified Commit af3337b6 authored by Greg Spencer's avatar Greg Spencer Committed by GitHub

Add Enter and Tab back in to ios and macos key maps (#81865)

I noticed that tab traversal stopped working on iOS when #73440 was landed.

It seems to be that the control characters were excluded from the list of logical keys, and so they ended up being generated values.

This PR just adds "Enter" and "Tab" to the list for both macOS and iOS.
parent df3662b1
{
"Backspace": ["Backspace"],
"Tab": ["Tab"],
"Enter": ["Enter"],
"Escape": ["Escape"],
"CapsLock": ["CapsLock"],
"NumLock": ["NumLock"],
......
......@@ -1383,6 +1383,12 @@
"web": [
"Tab"
],
"macOs": [
"Tab"
],
"ios": [
"Tab"
],
"gtk": [
"Tab",
"KP_Tab",
......@@ -1396,6 +1402,12 @@
]
},
"values": {
"macOs": [
48
],
"ios": [
43
],
"gtk": [
65289,
65417,
......@@ -1420,6 +1432,12 @@
"web": [
"Enter"
],
"macOs": [
"Enter"
],
"ios": [
"Enter"
],
"gtk": [
"Return",
"ISO_Enter",
......@@ -1433,6 +1451,12 @@
]
},
"values": {
"macOs": [
36
],
"ios": [
40
],
"gtk": [
65293,
65076,
......
{
"Backspace": ["Backspace"],
"Tab": ["Tab"],
"Enter": ["Enter"],
"Escape": ["Escape"],
"CapsLock": ["CapsLock"],
"Fn": ["Fn"],
......
......@@ -193,7 +193,7 @@ class LogicalKeyData {
// Make sure every Numpad key that we care about has been defined.
unusedNumpad.forEach((String key, String value) {
print('Unuadded numpad key $value');
print('Undefined numpad key $value');
});
}
......
......@@ -1226,6 +1226,8 @@ const Map<int, LogicalKeyboardKey> kMacOsFunctionKeyMap = <int, LogicalKeyboardK
/// have a character representation will be derived from their key codes using
/// this map.
const Map<int, LogicalKeyboardKey> kMacOsToLogicalKey = <int, LogicalKeyboardKey>{
36: LogicalKeyboardKey.enter,
48: LogicalKeyboardKey.tab,
51: LogicalKeyboardKey.backspace,
53: LogicalKeyboardKey.escape,
54: LogicalKeyboardKey.metaRight,
......@@ -1494,8 +1496,10 @@ const Map<int, LogicalKeyboardKey> kIosNumPadMap = <int, LogicalKeyboardKey>{
/// have a character representation will be derived from their key codes using
/// this map.
const Map<int, LogicalKeyboardKey> kIosToLogicalKey = <int, LogicalKeyboardKey>{
40: LogicalKeyboardKey.enter,
41: LogicalKeyboardKey.escape,
42: LogicalKeyboardKey.backspace,
43: LogicalKeyboardKey.tab,
57: LogicalKeyboardKey.capsLock,
58: LogicalKeyboardKey.f1,
59: LogicalKeyboardKey.f2,
......
......@@ -120,7 +120,8 @@ class RawKeyEventDataIos extends RawKeyEventData {
// printable. HOME, DEL, arrow keys, and function keys are considered
// modifier function keys, which generate invalid Unicode scalar values.
if (keyLabel.isNotEmpty &&
!LogicalKeyboardKey.isControlCharacter(keyLabel)) {
!LogicalKeyboardKey.isControlCharacter(keyLabel) &&
!_isUnprintableKey(keyLabel)) {
// Given that charactersIgnoringModifiers can contain a String of
// arbitrary length, limit to a maximum of two Unicode scalar values. It
// is unlikely that a keyboard would produce a code point bigger than 32
......@@ -154,6 +155,23 @@ class RawKeyEventDataIos extends RawKeyEventData {
return LogicalKeyboardKey(iosKeyIdPlane | keyCode | LogicalKeyboardKey.autogeneratedMask);
}
/// Returns true if the given label represents an unprintable key.
///
/// Examples of unprintable keys are "NSUpArrowFunctionKey = 0xF700"
/// or "NSHomeFunctionKey = 0xF729".
///
/// See <https://developer.apple.com/documentation/appkit/1535851-function-key_unicodes?language=objc> for more
/// information.
///
/// Used by [RawKeyEvent] subclasses to help construct IDs.
static bool _isUnprintableKey(String label) {
if (label.length != 1) {
return false;
}
final int codeUnit = label.codeUnitAt(0);
return codeUnit >= 0xF700 && codeUnit <= 0xF8FF;
}
bool _isLeftRightModifierPressed(KeyboardSide side, int anyMask, int leftMask, int rightMask) {
if (modifiers & anyMask == 0) {
return false;
......
......@@ -38,6 +38,7 @@ void main() {
test('Control characters are recognized as such', () async {
// Check some common control characters
expect(LogicalKeyboardKey.isControlCharacter('\x08'), isTrue); // BACKSPACE
expect(LogicalKeyboardKey.isControlCharacter('\x09'), isTrue); // TAB
expect(LogicalKeyboardKey.isControlCharacter('\x0a'), isTrue); // LINE FEED
expect(LogicalKeyboardKey.isControlCharacter('\x0d'), isTrue); // RETURN
expect(LogicalKeyboardKey.isControlCharacter('\x1b'), isTrue); // ESC
......@@ -48,6 +49,16 @@ void main() {
expect(LogicalKeyboardKey.isControlCharacter('~'), isFalse);
expect(LogicalKeyboardKey.isControlCharacter('\xa0'), isFalse); // NO-BREAK SPACE
});
test('Control characters are not using incorrect values', () async {
const int kUnprintablePlane = 0x01000000000;
// Check some common control characters to make sure they're using
// their char code values, and not something else.
expect(LogicalKeyboardKey.backspace.keyId, equals(kUnprintablePlane + 0x08));
expect(LogicalKeyboardKey.tab.keyId, equals(kUnprintablePlane + 0x09));
expect(LogicalKeyboardKey.enter.keyId, equals(kUnprintablePlane + 0x0d));
expect(LogicalKeyboardKey.escape.keyId, equals(kUnprintablePlane + 0x1b));
expect(LogicalKeyboardKey.delete.keyId, equals(kUnprintablePlane + 0x7f));
});
test('Basic synonyms can be looked up.', () async {
expect(LogicalKeyboardKey.shiftLeft.synonyms.first, equals(LogicalKeyboardKey.shift));
expect(LogicalKeyboardKey.controlLeft.synonyms.first, equals(LogicalKeyboardKey.control));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment