Repository navigation
SelectableText long press on iOS - #63994
Conversation
|
@chunhtai Am I misunderstanding how this should work? It seems like this behavior was deliberately removed from iOS along with lots of tests to confirm that long pressing in iOS doesn't allow selection. Take a look at the code changes I made and let me know. I left two TODOs in the code while I confirm that this is what we want to do. |
|
I copied the code from the original textfield, I am not sure why it was like this either. My guess is that probable has something to do with precision pointer like mouse or trackpad. cc @gspencergoog @dkwingsmt |
|
This pull request has been changed to a draft. The currently pending flutter-gold status will not be able to resolve until a new commit is pushed or the change is marked ready for review again. |
|
Another thing I've discovered while working on this is that edge scrolling doesn't seem to work: #64059 |
|
@gspencergoog and @dkwingsmt are there any special concerns for desktop/mouse text selection, and will I get myself into trouble by making the changes in this PR? Adding you as reviewers. |
|
I think as long as long press on a mouse doesn't select, it's probably fine. It should only happen from a touch long press. |
|
Ok got it. I'll plan to make these changes and just make sure that things work as I think they should, including longpressing with a mouse. I'll @ mention for review when I'm done. Thanks! |
…been broken. Remove Select All test, since Select All is no longer available
|
One more bug I noticed while working on this is that longpressing in a normal field on iOS doesn't seem to have the correct behavior either: #64190 |
| renderEditable.selectWordsInRange( | ||
| from: details.globalPosition - details.offsetFromOrigin, | ||
| to: details.globalPosition, | ||
| cause: SelectionChangedCause.longPress, | ||
| ); |
There was a problem hiding this comment.
Some of this code could probably be deduplicated between here, TextField, CupertinoTextField, and TextSelectionGestureDetectorBuilder, but I think I'll have to fix #64190 first. I'll make sure I clean up any deduplication when I fix that issue.
There was a problem hiding this comment.
Same with onSingleLongTapStart below.
There was a problem hiding this comment.
I just double check it seems like selectable text is correct, but there will be different for long press on textfield when it has keyboard focus vs when it does not
There was a problem hiding this comment.
I meant we probably can't merge those methods for selectableText and TextField/CupertinoTextField because they have different behavior when long pressed in native iOS
SelectableText -> always select the word
Textfield -> If keyboard focused, then move collapsed cursor to the word boundary and shows selectAll
-> if keyboard not focused, select the word
| }), | ||
| ); | ||
|
|
||
| testWidgets('The handles show after pressing Select All (iOS and Mac)', (WidgetTester tester) async { |
There was a problem hiding this comment.
I believe there is now no way to make Select All appear for a SelectableText on iOS, so I've removed this test.
There was a problem hiding this comment.
That seems consistent with native iOS in my experimentation.
| }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS })); | ||
| }, | ||
| variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }), | ||
| skip: true, // https://github.com/flutter/flutter/issues/64059 |
There was a problem hiding this comment.
I don't know why this test was passing in the first place, but it started failing when I made this change, despite the behavior it describes being broken either way. I've created the issue #64059 to deal with fixing it and unskipping it.
|
@gspencergoog @dkwingsmt @chunhtai Ready for final review. Here is the long press behavior on each platform now:
That seems consistent with native in all cases to me. |
| Feedback.forLongPress(_state.context); | ||
| break; | ||
| } | ||
| renderEditable.selectWord(cause: SelectionChangedCause.longPress); |
There was a problem hiding this comment.
How do we differentiate between precision devices? the mouse and stylus should not make a selection right?
There was a problem hiding this comment.
Hmm I'm not sure but that would make sense. @gspencergoog Didn't you have a keyboard and mouse setup for an Android device? Is there different behavior for longpressing with the mouse vs. a finger?
There was a problem hiding this comment.
for macOS at least, the mouse long press does not select the word
There was a problem hiding this comment.
That continues to work even after this change. The behavior on all 3 platforms is shown in #63994 (comment).
| renderEditable.selectWordsInRange( | ||
| from: details.globalPosition - details.offsetFromOrigin, | ||
| to: details.globalPosition, | ||
| cause: SelectionChangedCause.longPress, | ||
| ); |
There was a problem hiding this comment.
I just double check it seems like selectable text is correct, but there will be different for long press on textfield when it has keyboard focus vs when it does not
|
@chunhtai Is there an issue for that clipping bug? It's not something I've seen before I don't think. |
|
I don't think so, it is also hard to reproduce. I can only reproduce it on my physical device. |




Description
Previously, iOS did not allow selection with long press in SelectableText (only Android did). This PR enables it.
Related Issues
Closes #62658
Tests
I've updated existing tests to check the correct behavior. There were many tests that were testing incorrect behavior (that longpressing a word just shows the menu without selecting anything).