Skip to content

SelectableText long press on iOS - #63994

Merged
fluttergithubbot merged 6 commits into
flutter:masterfrom
justinmc:selectable-ios-long-press
Aug 28, 2020
Merged

fluttergithubbot merged 6 commits into
flutter:masterfrom
justinmc:selectable-ios-long-press

Conversation

@justinmc

@justinmc justinmc commented Aug 17, 2020 •

Copy link
Copy Markdown
Contributor

Description

Previously, iOS did not allow selection with long press in SelectableText (only Android did). This PR enables it.

Old New
old new

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).

@justinmc
justinmc requested a review from chunhtai August 17, 2020 20:48
@justinmc justinmc self-assigned this Aug 17, 2020
@flutter-dashboard flutter-dashboard Bot added p: material_ui material_ui package in flutter/packages framework flutter/packages/flutter repository. See also f: labels. labels Aug 17, 2020
@justinmc
justinmc marked this pull request as draft August 17, 2020 20:48
@justinmc

Copy link
Copy Markdown
Contributor Author

@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.

@chunhtai

Copy link
Copy Markdown
Contributor

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
If this is indeed the desire behavior we should probably update that? Furthermore, if we don't need two different version between CupertinoTextField and TextField/Selectable, we can update the parent method and don't need to override this method in the sub classes

@flutter-dashboard

Copy link
Copy Markdown

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.

@justinmc

Copy link
Copy Markdown
Contributor Author

Another thing I've discovered while working on this is that edge scrolling doesn't seem to work: #64059

@justinmc

Copy link
Copy Markdown
Contributor Author

@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.

@gspencergoog

Copy link
Copy Markdown
Contributor

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.

@justinmc

Copy link
Copy Markdown
Contributor Author

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
@justinmc

Copy link
Copy Markdown
Contributor Author

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

Comment on lines +75 to +79
renderEditable.selectWordsInRange(
from: details.globalPosition - details.offsetFromOrigin,
to: details.globalPosition,
cause: SelectionChangedCause.longPress,
);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with onSingleLongTapStart below.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chunhtai Are you talking about #64190 specifically or this PR?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe there is now no way to make Select All appear for a SelectableText on iOS, so I've removed this test.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@justinmc

Copy link
Copy Markdown
Contributor Author

@gspencergoog @dkwingsmt @chunhtai Ready for final review.

Here is the long press behavior on each platform now:

iOS Android Mac
Word selected, Copy shows. Word selected, Copy and Select All show. Nothing
Screen Shot 2020-08-19 at 2 54 09 PM Screen Shot 2020-08-19 at 2 54 06 PM Screen Shot 2020-08-19 at 2 54 28 PM

That seems consistent with native in all cases to me.

@justinmc
justinmc marked this pull request as ready for review August 20, 2020 18:55
Feedback.forLongPress(_state.context);
break;
}
renderEditable.selectWord(cause: SelectionChangedCause.longPress);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we differentiate between precision devices? the mouse and stylus should not make a selection right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for macOS at least, the mouse long press does not select the word

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That continues to work even after this change. The behavior on all 3 platforms is shown in #63994 (comment).

Comment on lines +75 to +79
renderEditable.selectWordsInRange(
from: details.globalPosition - details.offsetFromOrigin,
to: details.globalPosition,
cause: SelectionChangedCause.longPress,
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 chunhtai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, although I found a clipping issue that is parallel to this. I am using iphone XR

ezgif com-optimize

@justinmc

Copy link
Copy Markdown
Contributor Author

@chunhtai Is there an issue for that clipping bug? It's not something I've seen before I don't think.

@fluttergithubbot
fluttergithubbot merged commit 8f370df into flutter:master Aug 28, 2020
@chunhtai

Copy link
Copy Markdown
Contributor

I don't think so, it is also hard to reproduce. I can only reproduce it on my physical device.

@justinmc
justinmc deleted the selectable-ios-long-press branch August 28, 2020 19:47
mingwandroid pushed a commit to mingwandroid/flutter that referenced this pull request Sep 6, 2020
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Aug 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

framework flutter/packages/flutter repository. See also f: labels. p: material_ui material_ui package in flutter/packages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SelectableText has no selection handle on iOS when long press, only appears after choosing selecting all text

5 participants