Repository navigation
[EditableText] preserve selection/composition range on unfocus - #86796
fluttergithubbot merged 11 commits into
Conversation
Related Issue: flutter#79982 Let the selection/composition range of an `EditableText` survive through unfocus, and allows the original selection/composition range to be restored when the field regains focus.
|
@chunhtai I think you mentioned the desktop accessibility implementation specifically use |
There was a problem hiding this comment.
The buildTextSpan method has something similar (the composing region is not painted if the widget is readOnly). But this is a little bit too magical for a low level widget.
There was a problem hiding this comment.
Is it ever possible for a SelectableText to show its selection while another EditableText has focus?
There was a problem hiding this comment.
Doesn't seem possible, when a SelectableText loses focus the selection is set to TextRange.empty. Unless there's a SelectableText that initially has a non-empty selection and is not focused.
8f7fa0b to
03aede3
Compare
There was a problem hiding this comment.
Before the change the underline was shown even when the text field is not focused. That's why this test was passing without the additional pump.
03aede3 to
7303e34
Compare
That should be fine. |
justinmc
left a comment
There was a problem hiding this comment.
LGTM 👍 Just one question and some nits.
There was a problem hiding this comment.
I guess the caret was blinking when the field had a selection even when it wasn't focused.
There was a problem hiding this comment.
Any suggestions on process of recovering data with this issue
There was a problem hiding this comment.
EditableTextState does call _stopCursorTimer when the widget is unfocused. Reverting this change does not seem to break any tests so I undid the change.
There was a problem hiding this comment.
Is it ever possible for a SelectableText to show its selection while another EditableText has focus?
7303e34 to
dfdf9fd
Compare
|
Golden file changes have been found for this pull request. Click here to view and triage (e.g. because this is an intentional change). If you are still iterating on this change and are not ready to resolve the images on the Flutter Gold dashboard, consider marking this PR as a draft pull request above. You will still be able to view image results on the dashboard, commenting will be silenced, and the check will not try to resolve itself until marked ready for review. For more guidance, visit Writing a golden file test for Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
13c421d to
6dc779a
Compare
LongCatIsLooong
left a comment
There was a problem hiding this comment.
@justinmc I moved the focus selection highlight logic to high-level text fields. Could you take a look again?
There was a problem hiding this comment.
Doesn't seem possible, when a SelectableText loses focus the selection is set to TextRange.empty. Unless there's a SelectableText that initially has a non-empty selection and is not focused.
There was a problem hiding this comment.
EditableTextState does call _stopCursorTimer when the widget is unfocused. Reverting this change does not seem to break any tests so I undid the change.
justinmc
left a comment
There was a problem hiding this comment.
Changes LGTM minus a potential scuba failure, happy to look again when that's fixed.
| if (widget.focusNode != oldWidget.focusNode) { | ||
| (oldWidget.focusNode ?? _focusNode)?.removeListener(_handleFocusChanged); | ||
| (widget.focusNode ?? _focusNode)?.addListener(_handleFocusChanged); |
There was a problem hiding this comment.
I guess we weren't swapping these properly before 😁
There was a problem hiding this comment.
The _handleFocusChange listener is added in this PR. We didn't have to remove/add listeners before.
| minLines: widget.minLines, | ||
| expands: widget.expands, | ||
| selectionColor: selectionColor, | ||
| // Only show the selection highlight when the text field is focused. |
There was a problem hiding this comment.
Super nit: There was no corresponding comment in CupertinoTextField here.
Related Issue: #79982
Fixes #86752
Let the selection/composition range of an
EditableTextsurvive throughunfocus, and allows the original selection/composition range to be
restored when the field regains focus.
Demo
Unfortunately the selection handle (and the context menu) is gone when a text field regains focus. This probably needs a new issue since the current implementation of
_handleSelectionChanged(and the corresponding logic in the gesture detector callbacks) is really convoluted.ezgif.com-gif-maker.mp4
Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.