-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Fix text selection when user is dragging in the opposite direction #29395
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
| if (toPosition != null) { | ||
| baseOffset = math.min(fromPosition.offset, toPosition.offset); | ||
| extentOffset = math.max(fromPosition.offset, toPosition.offset); | ||
| } |
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.
I'm assuming the cursor positioning does not need adjustment?
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.
baseOffset and extendOffset represent the cursor (or the selection) state. When baseOffset === extentOffset, the cursor is displayed at that position. When they are different, then they represent a range selection and Flutter will draw a selection box instead.
Does that answer your question?
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.
From offline discussion. Editables do remember the position of the cursor even if it's not rendered. So if you Shift + Arrow to shrink or extend the selection it will move the side corresponding to the "extent". It's OK if we don't support it now, but we should track it somewhere. So maybe file an issue, and ping @gspencergoog so it doesn't get lost.
|
Is there an issue that outlines what this feature request is? It seems this isn't an existing UI pattern on Android. |
|
@xster there's no issue, but I'm happy to file one if necessary. The problem is if you drag from left to right, the text will be selected as expected. But if you drag from right to left, then |
|
Understood. Can you add some tests to the other non-mouse-kind users of selectPositionAt? i.e. in material and cupertino text_field_test.dart, check that on Android and iOS, you can't bring up the selection handles, then tap-hold one and drag it past the other one. It will, in the maximum case, just collapse the selection to 1 character. |
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]). This will ensure a smooth and quick review process.///).flutter analyze --flutter-repo) does not report any problems on my PR.Breaking Change
Does your PR require Flutter developers to manually update their apps to accommodate your change?