Ignore key events on edit control on web platform (#52656)#52661
Ignore key events on edit control on web platform (#52656)#52661fluttergithubbot merged 1 commit intoflutter:masterfrom
Conversation
|
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
|
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
There was a problem hiding this comment.
Instead of exposing this private method, I would initialize the flutter binding and uses
ServicesBinding.instance.defaultBinaryMessenger.handlePlatformMessage(
SystemChannels.keyEvent.name,
SystemChannels.keyEvent.codec.encodeMessage(data),
(ByteData data) {},
);There was a problem hiding this comment.
Good!. Thank you. :)
There was a problem hiding this comment.
As you suggested, I tried to use the ServicesBinding class.
It seems to be working if I use testWidgets and EditableText for pumpWidget. ( You can see it on updated pull-request's source code)
I failed to find a other solution to use both RenderEditable and ServicesBinding together without pumpWidget.
This test code is working well. but I am not sure if this is correct implementation under flutter testing rule. :(
There was a problem hiding this comment.
Sorry I forgot to mention you will need TestWidgetsFlutterBinding.ensureInitialized();
See
https://github.com/flutter/flutter/blob/master/packages/flutter/test/services/platform_channel_test.dart
There was a problem hiding this comment.
This comment is unclear, is the key down only apply to arrow key?
There was a problem hiding this comment.
This code and one more pull-request(I does't issue yet) on engine repo replace flutter engine's pull-request #13699. so ignore all keyEvent from input control on web.
Arrow key(_handleMovement function) and delete key(_handleDelete function) should be ignored.
But I didn't check the keys(ctrl+c, ctrl+v, ctrl+x and ctrl+a) which be handled in _handleShortcuts yet. I am going to check those keys should be ignored or not. then renew pull-request. Thank you.
There was a problem hiding this comment.
Ctrl+c, ctrl+v keys are working well. so I modify the code to ignore movement keys and delete key only.
Thank you.
There was a problem hiding this comment.
I am surprised that uses TestWidgetsFlutterBinding.ensureInitialized(); still requires testWidget. what was the issue you were facing? If this is necessary, this test should be put in editable_text_test.dart
There was a problem hiding this comment.
Without testWidgets and pumpWidget, I could't use SystemBinding. :(
I will paste error message and sample code I tried because this can be user error(I'm newbie on Flutter).
I don't like this code which uses EditableText here. It's good if I can implement without testWidgets and pumpWidget function. and in other case, I will move this test code to editable_text_test.dart as you said.
Thank you.
There was a problem hiding this comment.
I am surprised that uses
TestWidgetsFlutterBinding.ensureInitialized();still requires testWidget. what was the issue you were facing? If this is necessary, this test should be put in editable_text_test.dart
Sorry today I succeed to make test code without testWidgets and pumpWidget functions as you said. maybe I was a little bit confused about test framework. :(
I updated my pull-request. Thank you for your comments. :)
There was a problem hiding this comment.
just return code here and return null at line 115?
There was a problem hiding this comment.
This code is copied from _getKeyCode() function, this style is there. so I follow same style.
Anyway I think the style you suggest is better too. :)
There was a problem hiding this comment.
lets follow the same style here final int scanCode = platform == 'web' ? -1 : _getScanCode(physicalKey, platform);
There was a problem hiding this comment.
The reason we decided to let the browser handle all key events for us is because it's difficult to hardcode the handling of all keys.
For example, movement keys and delete are not the only ones we should ignore here. What about backspace, home, end, page-up, page-down, enter, etc?
Could you explain your use-case a bit more? Like, why do you need to listen to keys when the user is editing a text field?
There was a problem hiding this comment.
Hello thank you for your comment, :)
First, regarding the keys we should ignore on control,
We can ignore all keyEvent here instead of Engine level. If so, it has same result but we can use RawKeyListener with EditableText. (It's not available now due to engine level keyEvent preventation.)
About my use-case,
I need to implement short-cut key so I need RawKeyLisener for it.
For example,
When the user press ctrl+r key(any key promised), I want
(1) Popup dialog for recommanded text list,
(2) Reset to default text status,
(3) Change input dialog layout(normal user or expert user)
Future more, I want to implement powerful rich editor based on flutter platform. as far as I know, text_editing.dart service should be used for it. but I can't receive keyEvent from it. so it's impossible on web. :(
There was a problem hiding this comment.
Sorry for the delay. Yeah, those use-cases make sense.
5dea0b3 to
df97ef9
Compare
There was a problem hiding this comment.
this can just be
await simulateKeyDownEvent(LogicalKeyboardKey.arrowRight, platform: 'web');There was a problem hiding this comment.
Oh... I didn't know there is that global function. Thank you for shorten code.
9b93e7b to
3e51403
Compare
mdebbar
left a comment
There was a problem hiding this comment.
Could you also share the engine PR so we can review both at the same time?
There was a problem hiding this comment.
There's no need to check the type of the event. You should use the available constant kIsWeb.
And I would put this check in the beginning of the method to avoid doing unnecessary work like collapsing synonyms, etc.
There was a problem hiding this comment.
Thank you. I modify the source to use kIsWeb. so I also modify test function. I activate my test function on web platform but omit other test functions in editable_test.dart on web. :(
I'm not sure if it's rightapproach. please confirm new pull-request.
|
Overall, the PR looks good to me at this point (except the |
7b9acf5 to
3aed75d
Compare
|
(PR triage): This PR is blocked on flutter/engine#17242. |
|
I wonder when this pull-request is merged. |
|
@cjng96 I can merge the PRs. I think the framework PR should be merged first, correct? |
Yes, framework PR should be merged first. Thank you. |

Description
Ignore key event from web platform to prevent twice key action by one key press.
For now It's done on Flutter Engine's keyboard.dart code. but I move that code here since we can use a key event via RawKeyListener on web platform(It's working well on Android)
After this pull-request is merged, I will issue new pull-request on Flutter Engine that allowing to send keyEvent which occurs on input element with web.
Related Issues
#52656
#44133
Tests
I added the following tests:
editable_test.dart / ignore key event from web platform
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]). This will ensure a smooth and quick review process.///).flutter analyze --flutter-repo) does not report any problems on my PR.Breaking Change
Did any tests fail when you ran them? Please read Handling breaking changes.