Skip to content

Conversation

@justinmc
Copy link
Contributor

@justinmc justinmc commented May 3, 2022

Previously, it was possible to click and drag the text selection cursor with the mouse. This should only be possible on mobile with touch gestures.

Old New
out out

Fixes #102928

@justinmc justinmc self-assigned this May 3, 2022
@flutter-dashboard flutter-dashboard bot added 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. labels May 3, 2022
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the command there for a purpose?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope I forgot it there, thanks for catching that.

@justinmc justinmc force-pushed the mouse-drag-cursor branch from 53ac3a9 to 1205271 Compare May 4, 2022 18:22
@justinmc
Copy link
Contributor Author

justinmc commented May 4, 2022

@chunhtai I bisected this bug to your PR #98073. What do you think of this solution?

The analyzer failure seems messed up, I'll push a merge commit when master gets updated and see if that fixes it.

Copy link
Contributor

@chunhtai chunhtai left a comment

Choose a reason for hiding this comment

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

This seems to be a weird approach to disable mouse drag, I was wondering whether you can fix this by making _SelectionHandleOverlay to only accept touch gesture?

case TargetPlatform.windows:
break;
case TargetPlatform.android:
case TargetPlatform.iOS:
Copy link
Contributor

Choose a reason for hiding this comment

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

what about iOS with blue tooth mouse?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, I should actually try that and see what happens. I'm not sure how it handles showing the handles or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With the new solution, mobile platforms with a mouse will behave the same as desktop platforms with a mouse (clicking and dragging with a mouse will select, not drag the cursor).

@justinmc
Copy link
Contributor Author

justinmc commented May 6, 2022

The problem is that the underlying field needs to receive that drag gesture when using a mouse, so I would need to write a custom GestureDetector that receives touch drags but ignores mouse drags.

My thought was that we shouldn't be building this invisible handle there anyway, but after looking into it my current way isn't the right way to do that. The place to decide if a handle should be built or not is TextSelectionControls, but I don't think I can fix it there without a breaking change.

I'll investigate the touch-only GestureDetector and try to do that. Maybe I can look into a deeper refactor and not drawing the handle at all after my ContextMenu changes.

@justinmc justinmc requested a review from chunhtai May 17, 2022 21:52
@justinmc
Copy link
Contributor Author

@chunhtai I've implemented the touch-only gesture detector solution, ready for re-review.

Copy link
Contributor

@chunhtai chunhtai left a comment

Choose a reason for hiding this comment

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

Code looks good, just concern about the supported devices.

debugOwner: this,
// Selection handles can only be dragged by touch. Mouse
// events on the handle will select the text behind.
supportedDevices: <PointerDeviceKind>{ PointerDeviceKind.touch },
Copy link
Contributor

Choose a reason for hiding this comment

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

what about stylus?

and there is the wild card, PointerDeviceKind.unknown. as far as I know, adb comand and a11y command may use unknown. I think a11y is probably fine to be excluded. adb commands are usually used during integration test, which may expect to drag the selection handle. I am not sure whether that would be a valid use case though

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense, let me try adding stylus and unknown and make sure the tests still pass here.

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 added them plus separate tests for touch, stylus, and unknown (and the existing mouse test). Ready for re-review.

@justinmc justinmc force-pushed the mouse-drag-cursor branch from 9aa8499 to 7ec74d3 Compare May 18, 2022 20:14
@justinmc justinmc requested a review from chunhtai May 18, 2022 20:19
Copy link
Contributor

@chunhtai chunhtai left a comment

Choose a reason for hiding this comment

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

LGTM

@fluttergithubbot fluttergithubbot merged commit 715fcaa into flutter:master May 19, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 19, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request May 19, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request May 19, 2022
@justinmc justinmc deleted the mouse-drag-cursor branch May 19, 2022 16:51
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request May 21, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 30, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Aug 30, 2022
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.

[Desktop]TextField cursor can be dragged with a mouse

4 participants