-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Re-implement hardware keyboard text selection. #42879
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Re-implement hardware keyboard text selection. #42879
Conversation
665a38d to
d4c5f3c
Compare
justinmc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
There is an existing issue about Gboard's directional soft keyboard not working: #9419. It looks like this PR will make it easier to get that sort of thing working, would you agree? Just making sure you're aware that we'll have to support that at some point.
| onSelectionChanged(nextSelection, this, cause); | ||
| } | ||
|
|
||
| // TODO(goderbauer): doesn't handle extended grapheme clusters with more than one Unicode scalar value (https://github.com/flutter/flutter/issues/13404). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this TODO obsolete now or should we keep it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, you're right, this does still apply, but only because some parts of this code depend upon the length of a string in code points instead of extended grapheme clusters. I'll restore it and add more info.
| /// It is used, for example, to make sets of keys with members like | ||
| /// [controlRight] and [controlLeft] and convert that set to contain just | ||
| /// [control], so that the question "is any control key down?" can be asked. | ||
| static Set<LogicalKeyboardKey> collapseSynonyms(Set<LogicalKeyboardKey> input) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love static methods. This could even be directly unit tested if you want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LOL! Yeah, ok, added a test. Very subtle. :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😄
| ), | ||
| cause, | ||
| ); | ||
| if (onSelectionChanged == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do all of these checks if onSelectionChanged exist here instead of one check inside of _handleSelectionChanged?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the idea was to avoid doing the work needed to get to _handleSelectionChanged, but I think I'll move this up to _handleKeyEvent, and also a check in _handleSelectionChanged, since there are other call sites for it that aren't protected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good.
|
|
||
| await tester.pump(); // Wait for autofocus to take effect. | ||
|
|
||
| Future<void> sendKeys(List<LogicalKeyboardKey> keys, {bool shift = false, bool control = false}) async { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wondering if we had a good way to test hardware keyboard keys 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! I added that stuff last month because it was missing. It's turning out to be very useful.
|
Yes, it could make it easier to implement a fix for #9419, but we'd have to convert those events into calls to a method here. Probably we'd have to subscribe to some listener for those events, and refactor this class to handle either those or key events. In any case, it shouldn't be too bad. |
012c244 to
739b5c8
Compare
|
Sounds good about #9419. I'm going to add some notes in there about this for when I get to it. |
739b5c8 to
38c1485
Compare
|
Just to be sure. If I understand correctly, this code handles text selection at the flutter framework level using Embedders have control over the text input (and text selection/position). And existing embedders are making use of the On go-flutter, work has been done to implement keyboard selection/copy/paste at the embedder level. My question is, should go-flutter stop using the The linux shell also uses This PR isn't aligned with embedders, and handles are duplicate. My very personal opinion, I think putting these handles in the flutter framework makes embedders lighter which is a good thing. Waiting for #31366 to be merged so that platform specific bindings can be addressed. |
…4130) This adds support for the command key for text selection/editing on macOS. I had ported the text editing code (in #42879), but forgot to add support for the command key itself. This also adds a test that tests the text editing on multiple platforms instead of just testing Android. There appears to still be a bug (filed #44135) where we're losing key events sometimes on macOS, leaving some keys "stuck" on, but this PR at least allows the right key combinations to be used.
This re-implements keyboard text selection so that it will work on platforms other than Android (e.g. macOS, Linux, etc.). Also, fixed a number of bugs in editing selection via a hardware keyboard (unable to select backwards, incorrect conversion to ASCII when cutting to clipboard, lack of support for CTRL-SHIFT-ARROW word selection, etc.). Did not address the keyboard locale issues that remain, or add platform specific switches for the bindings. All that will need some more design work before implementing them. Related Issues Fixes flutter#31951
Description
This re-implements keyboard text selection so that it will work on platforms other than Android (e.g. macOS, Linux, etc.).
Also, fixed a number of bugs in editing selection via a hardware keyboard (unable to select backwards, incorrect conversion to ASCII when cutting to clipboard, lack of support for CTRL-SHIFT-ARROW word selection, etc.).
Did not address the keyboard locale issues that remain, or add platform specific switches for the bindings. All that will need some more design work before implementing them.
Related Issues
Fixes #31951
Tests
Breaking Change