mirror of
https://github.com/flutter/flutter
synced 2024-08-28 04:21:14 +00:00
[RawKeyboard] Allow inconsistent modifiers for Web (#114499)
Co-authored-by: Bruno Leroux <bruno.leroux@gmail.com>
This commit is contained in:
parent
fe5eb2db75
commit
5628ebf662
|
@ -209,7 +209,7 @@ class LogicalKeyboardKey extends KeyboardKey {
|
|||
/// Auto-generated IDs should be a rare occurrence: Flutter supports most keys.
|
||||
///
|
||||
/// Keys that generate Unicode characters (even if unknown to Flutter) will
|
||||
/// not return true for `isAutogenerated`, since they will be assigned a
|
||||
/// not return true for [isAutogenerated], since they will be assigned a
|
||||
/// Unicode-based code that will remain stable.
|
||||
///
|
||||
/// If Flutter adds support for a previously unsupported key code, the ID it
|
||||
|
|
|
@ -29,5 +29,6 @@
|
|||
"Shift": ["ShiftLeft", "ShiftLeft", "ShiftRight", null],
|
||||
"Control": ["ControlLeft", "ControlLeft", "ControlRight", null],
|
||||
"Alt": ["AltLeft", "AltLeft", "AltRight", null],
|
||||
"AltGraph": ["AltGraph", null, "AltGraph", null],
|
||||
"Meta": ["MetaLeft", "MetaLeft", "MetaRight", null]
|
||||
}
|
||||
|
|
|
@ -2755,6 +2755,7 @@ const Map<String, List<LogicalKeyboardKey?>> kWebLocationMap = <String, List<Log
|
|||
'8': <LogicalKeyboardKey?>[LogicalKeyboardKey.digit8, null, null, LogicalKeyboardKey.numpad8],
|
||||
'9': <LogicalKeyboardKey?>[LogicalKeyboardKey.digit9, null, null, LogicalKeyboardKey.numpad9],
|
||||
'Alt': <LogicalKeyboardKey?>[LogicalKeyboardKey.altLeft, LogicalKeyboardKey.altLeft, LogicalKeyboardKey.altRight, null],
|
||||
'AltGraph': <LogicalKeyboardKey?>[LogicalKeyboardKey.altGraph, null, LogicalKeyboardKey.altGraph, 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],
|
||||
|
|
|
@ -848,6 +848,12 @@ class RawKeyboard {
|
|||
_keysPressed[event.physicalKey] = logicalKey;
|
||||
}
|
||||
}
|
||||
// On Web, PhysicalKeyboardKey.altRight can be map to LogicalKeyboardKey.altGraph or
|
||||
// LogicalKeyboardKey.altRight:
|
||||
// https://github.com/flutter/flutter/issues/113836
|
||||
if (event.data is RawKeyEventDataWeb && event.physicalKey == PhysicalKeyboardKey.altRight) {
|
||||
_keysPressed[event.physicalKey] = event.logicalKey;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -842,6 +842,64 @@ void main() {
|
|||
expect(RawKeyboard.instance.keysPressed, contains(LogicalKeyboardKey.capsLock));
|
||||
}, skip: isBrowser); // [intended] This is an Android-specific group.
|
||||
|
||||
testWidgets('Allows inconsistent modifier for Web - Alt graph', (WidgetTester _) async {
|
||||
// Regression test for https://github.com/flutter/flutter/issues/113836
|
||||
final List<RawKeyEvent> events = <RawKeyEvent>[];
|
||||
RawKeyboard.instance.addListener(events.add);
|
||||
addTearDown(() {
|
||||
RawKeyboard.instance.removeListener(events.add);
|
||||
});
|
||||
await TestDefaultBinaryMessengerBinding.instance!.defaultBinaryMessenger.handlePlatformMessage(
|
||||
SystemChannels.keyEvent.name,
|
||||
SystemChannels.keyEvent.codec.encodeMessage(const <String, dynamic>{
|
||||
'type': 'keydown',
|
||||
'keymap': 'web',
|
||||
'code': 'AltRight',
|
||||
'key': 'AltGraph',
|
||||
'location': 2,
|
||||
'metaState': 0,
|
||||
'keyCode': 225,
|
||||
}),
|
||||
(ByteData? data) { },
|
||||
);
|
||||
|
||||
expect(events, hasLength(1));
|
||||
final RawKeyEvent altRightKey = events[0];
|
||||
final RawKeyEventDataWeb data = altRightKey.data as RawKeyEventDataWeb;
|
||||
expect(data.physicalKey, equals(PhysicalKeyboardKey.altRight));
|
||||
expect(data.logicalKey, equals(LogicalKeyboardKey.altGraph));
|
||||
expect(RawKeyboard.instance.keysPressed, contains(LogicalKeyboardKey.altGraph));
|
||||
}, skip: !isBrowser); // [intended] This is a Browser-specific test.
|
||||
|
||||
testWidgets('Allows inconsistent modifier for Web - Alt right', (WidgetTester _) async {
|
||||
// Regression test for https://github.com/flutter/flutter/issues/113836
|
||||
final List<RawKeyEvent> events = <RawKeyEvent>[];
|
||||
RawKeyboard.instance.addListener(events.add);
|
||||
addTearDown(() {
|
||||
RawKeyboard.instance.removeListener(events.add);
|
||||
});
|
||||
await TestDefaultBinaryMessengerBinding.instance!.defaultBinaryMessenger.handlePlatformMessage(
|
||||
SystemChannels.keyEvent.name,
|
||||
SystemChannels.keyEvent.codec.encodeMessage(const <String, dynamic>{
|
||||
'type': 'keydown',
|
||||
'keymap': 'web',
|
||||
'code': 'AltRight',
|
||||
'key': 'Alt',
|
||||
'location': 2,
|
||||
'metaState': 0,
|
||||
'keyCode': 225,
|
||||
}),
|
||||
(ByteData? data) { },
|
||||
);
|
||||
|
||||
expect(events, hasLength(1));
|
||||
final RawKeyEvent altRightKey = events[0];
|
||||
final RawKeyEventDataWeb data = altRightKey.data as RawKeyEventDataWeb;
|
||||
expect(data.physicalKey, equals(PhysicalKeyboardKey.altRight));
|
||||
expect(data.logicalKey, equals(LogicalKeyboardKey.altRight));
|
||||
expect(RawKeyboard.instance.keysPressed, contains(LogicalKeyboardKey.altRight));
|
||||
}, skip: !isBrowser); // [intended] This is a Browser-specific test.
|
||||
|
||||
testWidgets('Dispatch events to all handlers', (WidgetTester tester) async {
|
||||
final FocusNode focusNode = FocusNode();
|
||||
final List<int> logs = <int>[];
|
||||
|
|
Loading…
Reference in a new issue