-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Set selection on tap down for desktop platforms and tap up for mobile #105505
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
Set selection on tap down for desktop platforms and tap up for mobile #105505
Conversation
75fd559 to
1c977df
Compare
justinmc
left a comment
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.
LGTM with some nits 👍
| // On macOS/iOS/iPadOS a touch tap places the cursor at the edge | ||
| // of the word. |
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.
Nit: Would this comment be better above the touch case?
| break; | ||
| case TargetPlatform.iOS: | ||
| if (isShiftPressedValid) { | ||
| // On these platforms, a shift-tapped unfocused field expands from 0, |
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.
Nit: "these platforms" => "this platform" or "iOS"
| await gesture.down(gPos); | ||
| await tester.pumpAndSettle(); | ||
| expect(controller.selection.baseOffset, 8); | ||
| expect(controller.selection.extentOffset, 8); |
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.
Nit: Maybe do another gesture.up after this and expect that the selection is still the same? Maybe that's a waste, up to you.
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.
Added
|
|
||
| await touchGesture.down(gPos); | ||
| await tester.pumpAndSettle(); | ||
| // On iOS a tap to select, selects the word edge instead of the exact tap position. |
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.
Nit: "On iOS a tap to select," => "On iOS, a tap to select"
| expect(controller.selection.baseOffset, isTargetPlatformApple ? 4 : 5); | ||
| expect(controller.selection.extentOffset, isTargetPlatformApple ? 4 : 5); |
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.
Wait so on tap down it moves to 4/5, and then on tap up it goes to 8? I was expecting that on down it would do nothing.
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.
Oh I can see how this can be unclear. It moves to "4/5" on the last tap up before this tap down, but I check it after this tap down. I'll check it after the tap up as well to make it clearer.
| expect(controller.selection.baseOffset, 8); | ||
| expect(controller.selection.extentOffset, 26); | ||
| }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS })); | ||
| }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS })); |
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.
Good catch, I've seen this elsewhere too.
| expect(controller.selection.extentOffset, 23); | ||
|
|
||
| // Expand the selection a bit. | ||
| if (isTargetPlatformMobile) { |
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.
@justinmc This is where the 23->24 I was talking about is.
|
|
||
| // Expand the selection a bit. | ||
| if (isTargetPlatformMobile) { | ||
| await gesture.down(textOffsetToPosition(tester, 7)); |
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.
@justinmc The 8->7 I was referring to.
Could you confirm that this is an operating system difference instead of a touch device thing (e.g., touch versus mouse click)? |
On my pixel 6 pro tested on google keep with a mouse the selection is set on tap up. Same with touch. |
40e5d7e to
3d9f2fe
Compare
justinmc
left a comment
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.
LGTM 👍
Thanks for straightening this out!
| controller.selection, | ||
| const TextSelection.collapsed(offset: 7, affinity: TextAffinity.upstream), | ||
| ); | ||
| // Place collapsed selection. |
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.
Why did "Plain" change to "Place"?
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 thought it was a typo, but I understand what was meant by plain now. Changing it back.
| expect(controller.selection.baseOffset, isTargetPlatformMobile ? 7 : 6); | ||
| expect(controller.selection.extentOffset, isTargetPlatformMobile ? 7 : 6); |
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.
Nit: Not sure if this is better but here's another option:
expect(controller.selection.isCollapsed, isTrue);
expect(controller.selection.baseOffset, isTargetPlatformMobile ? 7 : 6);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.
And I think there are a few other places with the same pattern.
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 like that pattern. I'll change it, thanks!
| expect(controller.selection.baseOffset, 8); | ||
| expect(controller.selection.extentOffset, 8); | ||
| }, | ||
| variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.linux, TargetPlatform.macOS, TargetPlatform.windows }) |
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.
Nit: There's also TargetPlatformVariant.desktop FYI.
| expect(controller.selection.baseOffset, 8); | ||
| expect(controller.selection.extentOffset, 8); | ||
| }, | ||
| variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.android, TargetPlatform.fuchsia, TargetPlatform.iOS }) |
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.
Nit: And likewise there is TargetPlatformVariant.mobile.
631be8f to
d59bfd2
Compare
…flutter#105505) Co-authored-by: Renzo Olivares <[email protected]>
On desktop platforms such as MacOS, Linux, Windows, and Web, the selection in an input field should be set during a tap down on the input field at a position.
On mobile platforms such as Android, Fuchsia, and iOS, the selection in an input field should be set during a tap up on the input field at a position.
Pre-launch Checklist
///).