Remove code which skips keyEvent from input control on web (#17242)

This commit is contained in:
cjng96 2020-04-02 01:32:18 +09:00 committed by GitHub
parent efbc375ee5
commit 46277fd2ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 36 deletions

View File

@ -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':

View File

@ -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();