-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Text Editing Movement Keys via Shortcuts #75032
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
Conversation
…respond too all actions
…nt in RenderEditable
…ness logic is stored
…reDetector with deprecations
10ea1ba to
f2f4135
Compare
|
@LongCatIsLooong @goderbauer Updated with your suggestions and ready for re-review, thanks! One thing I didn't implement to look at: #75032 (comment) |
LongCatIsLooong
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 🎉
| /// * [DefaultTextEditingShortcuts], which maps keyboard keys to many of the | ||
| /// [Intent]s that are handled here. | ||
| /// * [WidgetsApp], which creates a DefaultTextEditingShortcuts. | ||
| class DefaultTextEditingActions extends StatelessWidget { |
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.
nit: is it possible to just subclass Actions?
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, and it saves a good amount of lines of code. Thanks for the suggestion. Same for Shortcuts as you mentioned below.
| @override | ||
| Widget build(BuildContext context) { | ||
| return Actions( | ||
| actions: <Type, Action<Intent>>{ |
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.
nit: isn't this just:
| actions: <Type, Action<Intent>>{ | |
| actions: _shortcutsActions, |
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.
Yeah, I had a big setup for handling other types of actions that I deleted. I'll simplify to just _shortcutActions for now.
| /// behavior. | ||
| /// * [WidgetsApp], which creates a DefaultTextEditingShortcuts. | ||
| class DefaultTextEditingShortcuts extends StatelessWidget { | ||
| /// Creates an instance of DefaultTextEditingShortcuts. |
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.
nit: this seems to say very little about what this is by itself. maybe:
Creates a [Shortcuts] widget that provides the default text editing shortcuts on the current platform (basically copying the first summary line of the class).
| /// respond to the [Intent]s in these shortcuts with the default text editing | ||
| /// behavior. | ||
| /// * [WidgetsApp], which creates a DefaultTextEditingShortcuts. | ||
| class DefaultTextEditingShortcuts extends StatelessWidget { |
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.
nit: this is basically a specialized Shortcuts widget. Maybe subclass Shortcuts too, so we get a shallower tree?
| } | ||
|
|
||
| @override | ||
| bool isEnabled(Intent intent) { |
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.
super nit:
| bool isEnabled(Intent intent) { | |
| bool isEnabled(T intent) { |
|
Would #77512 be in scope for this? It involves Shortcuts and Text Editing and is a simple but important missing feature for desktop. I don't necessarily want to create a PR right now if text editing is already being refactored. |
|
@TimWhiting I think that's not in scope for this PR, but thanks for bringing it to my attention. The Shortcuts approach for that might be viable, but we should figure out exactly how the behavior should work. Let's continue the discussion on #77512. |
goderbauer
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
|
@justinmc thanks for all the work on this PR! Love where things are headed with customizability of text editing. Inability to override shortcuts in a TextField has been a blocker for releasing a Flutter web app to production. Does this PR apply to Flutter web? If not, maybe I can create a separate issue to discuss the use case? I noticed the comment:
I wonder if there's a way to allow the browser to handle text editing but still allow overriding the default browser behavior by creating Shortcuts. |
|
@venkatd No problem, thank you for the reviews on this! I think everything should work as expected with web. See this thread above: #75032 (comment) So using a Shortcuts widget will allow you to intercept key events like up-arrow before they go to the web engine, just like they will also be intercepted on other platforms before being handled by the framework. This is important for us too, like for @shihaohong who is working on keyboard controls for Autocomplete now. If something doesn't work as expected let me know, though. I think Autocomplete will be the first use of this in the framework itself and it's not finished yet. |
|
@justinmc great to hear! Will give the master branch a try this week. |
This is the first PR to start migrating text editing to use Actions. See the design doc for the entire plan.
This PR focuses only on the arrow keys, including all modifier keys, but it also establishes the pattern for handling all keyboard, mouse, and touch events for text editing.
Example
This example shows how to use an additional Shortcuts widget to override some default text editing keyboard shortcuts to have new behavior. Instead of moving the cursor, alt + up/down will change the focused widget. See the docs for more examples.
Issues
Partial fix for #75004.
Closes #76121
Tests
Breaking changes
None.