Spacebar and enter in EditableText work with Inkwells#98469
Spacebar and enter in EditableText work with Inkwells#98469justinmc merged 3 commits intoflutter:masterfrom
Conversation
| // Keypresses in EditableText shouldn't activate anything in the tree above. | ||
| ActivateIntent: DoNothingAction(consumesKey: false), | ||
| ButtonActivateIntent: DoNothingAction(consumesKey: false), |
There was a problem hiding this comment.
Originally I tried a much more complicated solution. I tried to make an Action that disabled itself when an EditableText was focused.
I think this solution is much more elegant. Here the EditableText is saying that you can't activate anything while typing into it. I think this makes sense on its own in the context of EditableText.
There was a problem hiding this comment.
Ideally EditableText shouldn't be the one that has to deal with this. The key event should just be consumed by one of the text editing shortcuts and should never reach the inkwell. Would that be possible with the current Shortcuts mechanism?
There was a problem hiding this comment.
Unfortunately no if I understand you correctly. On the engine side, the key is first sent to the framework where Shortcuts has the chance to consume it. If it doesn't, then the engine sends it to the IME.
There may or may not be a better way to organize that... As it is, I think it makes sense to me that it's EditableText's responsibility to say that it wants these keys to go to the IME and not to be consumed by shortcuts. Maybe it would be better if I used Shortcuts and consumed the keys directly instead of the Intents?
// Inside EditableTextState's build method
child: Shortcuts(
shortcuts: <ShortcutActivator, Intent>{
SingleActivator(LogicalKeyboardKey.space): DoNothingAndStopPropagationIntent(),
SingleActivator(LogicalKeyboardKey.enter): DoNothingAndStopPropagationIntent(),
},There was a problem hiding this comment.
Don't we have DoNothingAndStopPropagationTextIntent which can only be handled by text fields? If we map space & enter to that intent in the default text editing shortcuts, when the current focus is a text field then the key event will be sent back to the engine/IME I think?
DoNothingAndStopPropagationTextIntent.
|
I think my comment got swallowed when I pushed a commit but your idea in your comment worked great, I've updated the PR. I didn't realize that was possible but it's a lot cleaner 👍 |
Fixes a bug especially with text fields in a ListTile where space and enter didn't work.
Previously, an EditableText with an Inkwell above it couldn't input space or enter. The Inkwell would receive the key instead of the EditableText. This PR tells EditableText to consume ActivateIntents, because keypresses while entering text into an EditableText shouldn't activate anything.
Fixes #98322