Skip to content
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

Fix edge scrolling on platforms that select word by word on long press move #113128

Merged
merged 8 commits into from Oct 24, 2022

Conversation

Renzo-Olivares
Copy link
Contributor

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

This change moves the long press logic from the material layer (TextField) back into the widgets layer (TextSelection). This includes changing the long press behavior to match the platform behavior on CupertinoTextField and TextField. Previously in some cases CupertinoTextField and TextField attempted to match the behavior of the theme rather than the platform, this resulted in CupertinoTextField for Android having iOS text gestures.

This change fixes edge scrolling on long press by using the same technique used during drag to select text. We offset the new selection baseOffset by the editable and scrollable offsets. We also bring the selection into view for all platforms now on a long press or drag.

Before After
192354969-dd6cc2d4-4612-461b-a997-9b1eaa46ea0a Screen Recording 2022-10-10 at 12 03 34 PM

Fixes #26394

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. 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 Oct 7, 2022
Renzo Olivares added 2 commits Oct 7, 2022
Copy link
Contributor

@justinmc justinmc left a comment

LGTM with nits 👍

Thanks for cleaning this up, I'm happy to get this logic out of widgets like TextField and into more separate and reusable places.

Don't forget you have a merge conflict.

@@ -1561,7 +1561,7 @@ void main() {
expect(text.style!.fontWeight, FontWeight.w400);
}, skip: isContextMenuProvidedByPlatform); // [intended] only applies to platforms where we supply the context menu.

testWidgets('text field toolbar options correctly changes options', (WidgetTester tester) async {
testWidgets('text field toolbar options correctly changes options on Apple Platforms', (WidgetTester tester) async {
Copy link
Contributor

@justinmc justinmc Oct 20, 2022

Choose a reason for hiding this comment

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

FYI I'm deprecating toolbarOptions in my context menu PR. I worry that these tests might get deleted when toolbarOptions is removed a year from now. Maybe change the title to indicate that they're testing longpress behavior too? If you think they should not be deleted.

Copy link
Contributor Author

@Renzo-Olivares Renzo-Olivares Oct 24, 2022

Choose a reason for hiding this comment

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

I think we can delete these tests with the deprecation. There are other tests that more implicitly test long press. This test also doesn't test for long press on apple platforms since they do not select a word on long press, only move the cursor.

const TextSelection(baseOffset: 0, extentOffset: 7, affinity: TextAffinity.upstream),
);

// non-Collapsed toolbar shows 3 buttons.
Copy link
Contributor

@justinmc justinmc Oct 20, 2022

Choose a reason for hiding this comment

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

Nit: Capitalize the first letter.

expect(find.byKey(fakeMagnifier.key!), findsNothing);
}, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.android }));

testWidgets('Can long press to show, unshow, and update magnifier on Apple platforms', (WidgetTester tester) async {
Copy link
Contributor

@justinmc justinmc Oct 20, 2022

Choose a reason for hiding this comment

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

Super nit: Should this just say "on iOS"?

@@ -2360,7 +2360,7 @@ void main() {
break;
}
},
variant: TargetPlatformVariant.all(),
variant: TargetPlatformVariant.all(excluding: <TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }),
Copy link
Contributor

@justinmc justinmc Oct 20, 2022

Choose a reason for hiding this comment

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

Nit: Change the title to say "on Apple platforms"?

Copy link
Contributor Author

@Renzo-Olivares Renzo-Olivares Oct 24, 2022

Choose a reason for hiding this comment

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

You're right. This also reminds me that I should add a test for Apple/non-Apple platforms.

@Renzo-Olivares Renzo-Olivares added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 24, 2022
@auto-submit auto-submit bot merged commit 3c2f500 into flutter:master Oct 24, 2022
66 checks passed
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. autosubmit Merge PR when tree becomes green via auto submit App 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.

Long press drag on Android selects word and expands selection by words
2 participants