Skip to content

Conversation

@justinmc
Copy link
Contributor

@justinmc justinmc commented Dec 13, 2021

After #93835 added support for shift + tap to expand text selection in an input, this PR will add support for shift + tap and then dragging to move the extent.

Fixes #91979

Mac has some non-trivial behavior that made this PR more complex than I thought it would be. When the selection is inverted, it restores the original selection from the time of tapdown. See this video, which shows this PR duplicating Mac's behavior.

Screen.Recording.2021-12-13.at.3.58.56.PM.mov

@justinmc justinmc self-assigned this Dec 13, 2021
@flutter-dashboard flutter-dashboard bot added a: text input Entering text in a text field or keyboard related problems f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Dec 13, 2021
@justinmc justinmc marked this pull request as ready for review December 14, 2021 20:49
@flutter-dashboard flutter-dashboard bot added the f: cupertino flutter/packages/flutter/cupertino repository label Dec 14, 2021
Copy link
Contributor

@dkwingsmt dkwingsmt Jan 24, 2022

Choose a reason for hiding this comment

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

Maybe add one more step of moving the mouse after releasing the shift key, which, according to my test on macOS, continues the range selection.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added. Thanks for catching that, I didn't think to try it.

@dkwingsmt
Copy link
Contributor

dkwingsmt commented Jan 24, 2022

Another behavior we might be interested in testing is shift-tapping a text field when it is not focused.

  • On macOS this is equivalent to having the base offset as 0 (i.e. selecting the range from 0 to the mouse position).
  • On Windows the base offset seems to be the last position of the mouse before unfocused.

@dkwingsmt
Copy link
Contributor

dkwingsmt commented Jan 24, 2022

Another behavior worth checking is shift-tapping multiple times (instead of dragging).

  • On Windows it is simple: the base offset is never changed.
  • On macOS it has a complicated behavior: if the tapped position is closer to the start of the range, then the start is changed; otherwise the end is changed. Tapping at the exact mid-point changes the start.

(Sorry for adding complexity that might be beyond the scope of this PR. Should I file them as separate issues?)

Copy link
Contributor

@dkwingsmt dkwingsmt left a comment

Choose a reason for hiding this comment

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

I see no problem in this PR, but I suggest adding one extra step as commented above.

@justinmc
Copy link
Contributor Author

@dkwingsmt Thanks for thinking about all of these other behaviors. There are so many edge cases when it comes to stuff like this.

  • Shift + tap unfocused: The current behavior of Flutter seems to be the same as Windows. I've opened a separate issue for getting this right on Mac and will open a new PR soon: Shift tap on an unfocused field #97534
  • Shift tapping multiple times: I think we've got this working correctly, but tell me if you can break it. The complicated Mac logic is here.

I'll go ahead and merge this PR when/if it goes green.

@justinmc
Copy link
Contributor Author

Here's the PR for shift-tapping on an unfocused field: #97543

Copy link
Contributor

Choose a reason for hiding this comment

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

is it true that _shiftTapDragSelection != null if and only if _isShiftTapping is true? If so then you need only one variable to track the state?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not true unfortunately. _isShiftTapping will be true when just shift tapping (not dragging) while _shiftTapDragSelection will be null.

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: What if renderEditable.selection is invalid at this point?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I intended to prevent that with the if above, I'll update it so it can't be null here.

engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 8, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 8, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 8, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 8, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 8, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 8, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 8, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 8, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 8, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 8, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 8, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 8, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 8, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 8, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 8, 2022
clocksmith pushed a commit to clocksmith/flutter that referenced this pull request Mar 8, 2022
Supports the desktop text editing interaction of holding shift, tapping the field, and dragging to modify the selection.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TextField: issues with selection using shift+mouse click on the web

3 participants