Skip to content

Conversation

@Renzo-Olivares
Copy link
Contributor

@Renzo-Olivares Renzo-Olivares commented Jun 7, 2022

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

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I signed the [CLA].
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is [test-exempt].
  • All existing and new tests are passing.

@flutter-dashboard flutter-dashboard bot added a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels. labels Jun 7, 2022
@Renzo-Olivares Renzo-Olivares marked this pull request as ready for review June 9, 2022 21:11
@flutter-dashboard flutter-dashboard bot added f: material design flutter/packages/flutter/material repository. f: cupertino flutter/packages/flutter/cupertino repository labels Jun 9, 2022
Copy link
Contributor

@justinmc justinmc left a 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 👍

Comment on lines 1506 to 1507
// On macOS/iOS/iPadOS a touch tap places the cursor at the edge
// of the word.
Copy link
Contributor

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,
Copy link
Contributor

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"

Comment on lines +2928 to +2947
await gesture.down(gPos);
await tester.pumpAndSettle();
expect(controller.selection.baseOffset, 8);
expect(controller.selection.extentOffset, 8);
Copy link
Contributor

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.

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


await touchGesture.down(gPos);
await tester.pumpAndSettle();
// On iOS a tap to select, selects the word edge instead of the exact tap position.
Copy link
Contributor

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"

Comment on lines +2978 to +3003
expect(controller.selection.baseOffset, isTargetPlatformApple ? 4 : 5);
expect(controller.selection.extentOffset, isTargetPlatformApple ? 4 : 5);
Copy link
Contributor

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.

Copy link
Contributor Author

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 }));
Copy link
Contributor

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) {
Copy link
Contributor Author

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));
Copy link
Contributor Author

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.

@LongCatIsLooong
Copy link
Contributor

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.

Could you confirm that this is an operating system difference instead of a touch device thing (e.g., touch versus mouse click)?

@Renzo-Olivares
Copy link
Contributor Author

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.

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.
On my iPad with a mouse the selection is set on tap up, to the precise click location. With touch it is set to the word edge closest to the tap location. Both happen on tap up."
On macOS tap on trackpad or click on track pad sets the selection on tap down. Not sure if there is a way to simulate "touch".
On Windows the selection is set on tap down with a mouse. I'm not able to confirm if this is the same with a touchscreen windows device.
On Linux the selection is set on tap down with a mouse. I'm not able to confirm if this is the same with a touchscreen linux device.

@Renzo-Olivares Renzo-Olivares requested a review from justinmc June 29, 2022 00:21
@flutter-dashboard flutter-dashboard bot added the f: focus Focus traversal, gaining or losing focus label Jun 29, 2022
Copy link
Contributor

@justinmc justinmc left a 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.
Copy link
Contributor

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"?

Copy link
Contributor Author

@Renzo-Olivares Renzo-Olivares Jun 29, 2022

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.

Comment on lines 1787 to 1788
expect(controller.selection.baseOffset, isTargetPlatformMobile ? 7 : 6);
expect(controller.selection.extentOffset, isTargetPlatformMobile ? 7 : 6);
Copy link
Contributor

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);

Copy link
Contributor

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.

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 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 })
Copy link
Contributor

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 })
Copy link
Contributor

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.

@Renzo-Olivares Renzo-Olivares merged commit 4c1d887 into flutter:master Jun 29, 2022
@Renzo-Olivares Renzo-Olivares deleted the select_on_tapdown branch June 29, 2022 23:35
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Jun 30, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 30, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 30, 2022
camsim99 pushed a commit to camsim99/flutter that referenced this pull request Aug 10, 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: focus Focus traversal, gaining or losing focus 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.

3 participants