mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Remove code which skips keyEvent from input control on web (flutter/engine#17242)
This commit is contained in:
parent
72f8d80c66
commit
fdfb501df7
@ -5,22 +5,6 @@
|
||||
// @dart = 2.6
|
||||
part of engine;
|
||||
|
||||
/// Contains a whitelist of keys that must be sent to Flutter under all
|
||||
/// circumstances.
|
||||
///
|
||||
/// When keys are pressed in a text field, we generally don't want to send them
|
||||
/// to Flutter. This list of keys is the exception to that rule. Keys in this
|
||||
/// list will be sent to Flutter even if pressed in a text field.
|
||||
///
|
||||
/// A good example is the "Tab" and "Shift" keys which are used by the framework
|
||||
/// to move focus between text fields.
|
||||
const List<String> _alwaysSentKeys = <String>[
|
||||
'Alt',
|
||||
'Control',
|
||||
'Meta',
|
||||
'Shift',
|
||||
'Tab',
|
||||
];
|
||||
|
||||
/// Provides keyboard bindings, such as the `flutter/keyevent` channel.
|
||||
class Keyboard {
|
||||
@ -72,10 +56,6 @@ class Keyboard {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_shouldIgnoreEvent(event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_shouldPreventDefault(event)) {
|
||||
event.preventDefault();
|
||||
}
|
||||
@ -92,20 +72,6 @@ class Keyboard {
|
||||
_messageCodec.encodeMessage(eventData), _noopCallback);
|
||||
}
|
||||
|
||||
/// Whether the [Keyboard] class should ignore the given [html.KeyboardEvent].
|
||||
///
|
||||
/// When this method returns true, it prevents the keyboard event from being
|
||||
/// sent to Flutter.
|
||||
bool _shouldIgnoreEvent(html.KeyboardEvent event) {
|
||||
// Keys in the [_alwaysSentKeys] list should never be ignored.
|
||||
if (_alwaysSentKeys.contains(event.key)) {
|
||||
return false;
|
||||
}
|
||||
// Other keys should be ignored if triggered on a text field.
|
||||
return event.target is html.Element &&
|
||||
HybridTextEditing.isEditingElement(event.target);
|
||||
}
|
||||
|
||||
bool _shouldPreventDefault(html.KeyboardEvent event) {
|
||||
switch (event.key) {
|
||||
case 'Tab':
|
||||
|
||||
@ -242,7 +242,7 @@ void main() {
|
||||
Keyboard.instance.dispose();
|
||||
});
|
||||
|
||||
test('ignores keyboard events triggered on text fields', () {
|
||||
test('keyboard events should be triggered on text fields', () {
|
||||
Keyboard.initialize();
|
||||
|
||||
int count = 0;
|
||||
@ -260,7 +260,7 @@ void main() {
|
||||
);
|
||||
|
||||
expect(event.defaultPrevented, isFalse);
|
||||
expect(count, 0);
|
||||
expect(count, 1);
|
||||
});
|
||||
|
||||
Keyboard.instance.dispose();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user