Skip to content

Conversation

@mdebbar
Copy link
Contributor

@mdebbar mdebbar commented Mar 14, 2019

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.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • My PR includes tests for all changed/updated/fixed behaviors (See Test Coverage).
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require Flutter developers to manually update their apps to accommodate your change?

if (toPosition != null) {
baseOffset = math.min(fromPosition.offset, toPosition.offset);
extentOffset = math.max(fromPosition.offset, toPosition.offset);
}
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor

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.

@mdebbar mdebbar requested a review from jslavitz March 15, 2019 16:38
@goderbauer goderbauer added framework flutter/packages/flutter repository. See also f: labels. a: text input Entering text in a text field or keyboard related problems labels Mar 15, 2019
@mdebbar mdebbar merged commit 5787fc3 into flutter:master Mar 15, 2019
@xster
Copy link
Member

xster commented Mar 15, 2019

Is there an issue that outlines what this feature request is? It seems this isn't an existing UI pattern on Android.

@mdebbar
Copy link
Contributor Author

mdebbar commented Mar 15, 2019

@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 baseOffset will be greater than extentOffset and it'll be collapsed down to a cursor. So dragging from right to left is broken, and this PR fixes it.

@xster
Copy link
Member

xster commented Mar 15, 2019

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants