Unverified Commit 13bf7515 authored by moko256's avatar moko256 Committed by GitHub

Web: treat modifier key without location (#98460)

parent 301822f5
......@@ -26,8 +26,8 @@
"-": ["Minus", null, null, "NumpadSubtract"],
"+": ["Add", null, null, "NumpadAdd"],
"Enter": ["Enter", null, null, "NumpadEnter"],
"Shift": [null, "ShiftLeft", "ShiftRight", null],
"Control": [null, "ControlLeft", "ControlRight", null],
"Alt": [null, "AltLeft", "AltRight", null],
"Meta": [null, "MetaLeft", "MetaRight", null]
"Shift": ["ShiftLeft", "ShiftLeft", "ShiftRight", null],
"Control": ["ControlLeft", "ControlLeft", "ControlRight", null],
"Alt": ["AltLeft", "AltLeft", "AltRight", null],
"Meta": ["MetaLeft", "MetaLeft", "MetaRight", null]
}
......@@ -2760,22 +2760,22 @@ const Map<String, List<LogicalKeyboardKey?>> kWebLocationMap = <String, List<Log
'7': <LogicalKeyboardKey?>[LogicalKeyboardKey.digit7, null, null, LogicalKeyboardKey.numpad7],
'8': <LogicalKeyboardKey?>[LogicalKeyboardKey.digit8, null, null, LogicalKeyboardKey.numpad8],
'9': <LogicalKeyboardKey?>[LogicalKeyboardKey.digit9, null, null, LogicalKeyboardKey.numpad9],
'Alt': <LogicalKeyboardKey?>[null, LogicalKeyboardKey.altLeft, LogicalKeyboardKey.altRight, null],
'Alt': <LogicalKeyboardKey?>[LogicalKeyboardKey.altLeft, LogicalKeyboardKey.altLeft, LogicalKeyboardKey.altRight, null],
'ArrowDown': <LogicalKeyboardKey?>[LogicalKeyboardKey.arrowDown, null, null, LogicalKeyboardKey.numpad2],
'ArrowLeft': <LogicalKeyboardKey?>[LogicalKeyboardKey.arrowLeft, null, null, LogicalKeyboardKey.numpad4],
'ArrowRight': <LogicalKeyboardKey?>[LogicalKeyboardKey.arrowRight, null, null, LogicalKeyboardKey.numpad6],
'ArrowUp': <LogicalKeyboardKey?>[LogicalKeyboardKey.arrowUp, null, null, LogicalKeyboardKey.numpad8],
'Clear': <LogicalKeyboardKey?>[LogicalKeyboardKey.clear, null, null, LogicalKeyboardKey.numpad5],
'Control': <LogicalKeyboardKey?>[null, LogicalKeyboardKey.controlLeft, LogicalKeyboardKey.controlRight, null],
'Control': <LogicalKeyboardKey?>[LogicalKeyboardKey.controlLeft, LogicalKeyboardKey.controlLeft, LogicalKeyboardKey.controlRight, null],
'Delete': <LogicalKeyboardKey?>[LogicalKeyboardKey.delete, null, null, LogicalKeyboardKey.numpadDecimal],
'End': <LogicalKeyboardKey?>[LogicalKeyboardKey.end, null, null, LogicalKeyboardKey.numpad1],
'Enter': <LogicalKeyboardKey?>[LogicalKeyboardKey.enter, null, null, LogicalKeyboardKey.numpadEnter],
'Home': <LogicalKeyboardKey?>[LogicalKeyboardKey.home, null, null, LogicalKeyboardKey.numpad7],
'Insert': <LogicalKeyboardKey?>[LogicalKeyboardKey.insert, null, null, LogicalKeyboardKey.numpad0],
'Meta': <LogicalKeyboardKey?>[null, LogicalKeyboardKey.metaLeft, LogicalKeyboardKey.metaRight, null],
'Meta': <LogicalKeyboardKey?>[LogicalKeyboardKey.metaLeft, LogicalKeyboardKey.metaLeft, LogicalKeyboardKey.metaRight, null],
'PageDown': <LogicalKeyboardKey?>[LogicalKeyboardKey.pageDown, null, null, LogicalKeyboardKey.numpad3],
'PageUp': <LogicalKeyboardKey?>[LogicalKeyboardKey.pageUp, null, null, LogicalKeyboardKey.numpad9],
'Shift': <LogicalKeyboardKey?>[null, LogicalKeyboardKey.shiftLeft, LogicalKeyboardKey.shiftRight, null],
'Shift': <LogicalKeyboardKey?>[LogicalKeyboardKey.shiftLeft, LogicalKeyboardKey.shiftLeft, LogicalKeyboardKey.shiftRight, null],
};
/// Maps Windows KeyboardEvent codes to the matching [LogicalKeyboardKey].
......
......@@ -2479,6 +2479,14 @@ void main() {
RawKeyEventDataWeb.modifierScrollLock: ModifierKey.scrollLockModifier,
};
const Map<String, LogicalKeyboardKey> modifierTestsWithNoLocation =
<String, LogicalKeyboardKey>{
'Alt': LogicalKeyboardKey.altLeft,
'Shift': LogicalKeyboardKey.shiftLeft,
'Control': LogicalKeyboardKey.controlLeft,
'Meta': LogicalKeyboardKey.metaLeft,
};
test('modifier keys are recognized individually', () {
for (final int modifier in modifierTests.keys) {
final RawKeyEvent event = RawKeyEvent.fromMessage(<String, Object?>{
......@@ -2539,6 +2547,19 @@ void main() {
}
});
test('modifier keys with no location are mapped to left', () {
for (final String modifierKey in modifierTestsWithNoLocation.keys) {
final RawKeyEvent event = RawKeyEvent.fromMessage(<String, Object?>{
'type': 'keydown',
'keymap': 'web',
'key': modifierKey,
'location': 0,
});
final RawKeyEventDataWeb data = event.data as RawKeyEventDataWeb;
expect(data.logicalKey, modifierTestsWithNoLocation[modifierKey]);
}
});
test('Lower letter keys are correctly translated', () {
final RawKeyEvent keyAEvent = RawKeyEvent.fromMessage(const <String, Object?>{
'type': 'keydown',
......
......@@ -169,7 +169,7 @@ class KeyEventSimulator {
static _WebKeyLocationPair _getWebKeyLocation(LogicalKeyboardKey key, String keyLabel) {
String? result;
for (final MapEntry<String, List<LogicalKeyboardKey?>> entry in kWebLocationMap.entries) {
final int foundIndex = entry.value.indexOf(key);
final int foundIndex = entry.value.lastIndexOf(key);
// If foundIndex is -1, then the key is not defined in kWebLocationMap.
// If foundIndex is 0, then the key is in the standard part of the keyboard,
// but we have to check `keyLabel` to see if it's remapped or modified.
......
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