Set selection on tap down for desktop platforms and tap up for mobile#105505
Set selection on tap down for desktop platforms and tap up for mobile#105505Renzo-Olivares merged 21 commits intoflutter:masterfrom
Conversation
75fd559 to
1c977df
Compare
| // On macOS/iOS/iPadOS a touch tap places the cursor at the edge | ||
| // of the word. |
There was a problem hiding this comment.
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.
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.
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.
|
|
||
| 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.
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.
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.
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.
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.
@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)); |
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.
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.
Why did "Plain" change to "Place"?
There was a problem hiding this comment.
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.
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.
And I think there are a few other places with the same pattern.
There was a problem hiding this comment.
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.
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.
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
///).