Thanks to visit codestin.com
Credit goes to github.com

Skip to content

"Select All" Automatically scrolls EditableText to the end of the text field, which doesn't happen on native iOS #105799

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

Merged
merged 1 commit into from
Jul 29, 2022

Conversation

antholeole
Copy link
Contributor

@antholeole antholeole commented Jun 10, 2022

Fixes:

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 10, 2022
@@ -207,7 +207,6 @@ abstract class TextSelectionControls {
/// by the user.
void handleSelectAll(TextSelectionDelegate delegate) {
delegate.selectAll(SelectionChangedCause.toolbar);
delegate.bringIntoView(delegate.textEditingValue.selection.extent);
Copy link
Contributor Author

@antholeole antholeole Jun 10, 2022

Choose a reason for hiding this comment

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

I believe this is redundant: it seems like the default editableTextState.selectAll calls scrollIntoView. Nothing that tests this directly, either

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like you're right and it should be removed. I'll be deprecating handleSelectAll soon and hopefully removing the opportunity for things like this to happen.

@antholeole antholeole changed the title Toolbar SelectAll fixes "Select All" Automatically scrolls EditableText to the end of the text field, which doesn't happen on native iOS Jun 10, 2022
@antholeole antholeole requested review from LongCatIsLooong and Renzo-Olivares and removed request for Renzo-Olivares and LongCatIsLooong June 13, 2022 16:57
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.

Thanks for fixing this as a small separate PR. Just some small comments and questions but overall it looks good.

@@ -1796,8 +1796,20 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
),
cause,
);

/// The only known current platform that does not bring into view is iOS.
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be a double slash.

@@ -207,7 +207,6 @@ abstract class TextSelectionControls {
/// by the user.
void handleSelectAll(TextSelectionDelegate delegate) {
delegate.selectAll(SelectionChangedCause.toolbar);
delegate.bringIntoView(delegate.textEditingValue.selection.extent);
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like you're right and it should be removed. I'll be deprecating handleSelectAll soon and hopefully removing the opportunity for things like this to happen.

@@ -529,7 +528,7 @@ class TextSelectionOverlay {
}
}

/// An object that manages a pair of selection handles.
/// An object that manages a pair of selection handles and a toolbar.
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!

final TextEditingController controller = TextEditingController(text: text);
final ScrollController scrollController = ScrollController();
group('Selection changed scroll into view', () {
final String text = List<int>.generate(64, (int index) => index).join('\n');
Copy link
Contributor

Choose a reason for hiding this comment

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

The indentation is wrong here, this should be outdented.


final TextSelectionDelegate textSelectionDelegate = key.currentState!;
/// Populate [maxScrollExtent]
Copy link
Contributor

Choose a reason for hiding this comment

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

Period here.

await resetSelectionAndScrollOffset(tester, false);
textSelectionDelegate.selectAll(SelectionChangedCause.toolbar);
await tester.pump();
expect(scrollController.offset.roundToDouble(), maxScrollExtent);
Copy link
Contributor

Choose a reason for hiding this comment

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

I would have thought that this test would also be run on iOS and that it shouldn't scroll in that case (0.0), but it looks like it's passing so I'm wrong. What am I misunderstanding?

Copy link
Contributor Author

@antholeole antholeole Jun 17, 2022

Choose a reason for hiding this comment

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

"In a test environment, the platform returned is TargetPlatform.android regardless of the host platform." from here. You're right that this is implicit and looks weird... I read this when I was writing the code, but your comment had me scratching my head for a little because it's so implicit :). I'll explicitly run it on all other platforms but skip mac and iOS.

Copy link
Contributor

Choose a reason for hiding this comment

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

Or in EditableText should you be switching on Theme.of(context).targetPlatform instead of defaultTargetPlatform?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Talked offline - defaultTargetPlatform seems better in this case

Comment on lines 11280 to 11281
expect(scrollController.offset, 0.0);
}, variant: const TargetPlatformVariant(<TargetPlatform>{ 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: Would it be useful to run this test on all platforms and put this final expect in a switch to show what the different behavior is? Or maybe that's covered by the next test anyway.

@@ -1796,8 +1796,20 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
),
cause,
);

/// The only known current platform that does not bring into view is iOS.
if (cause == SelectionChangedCause.toolbar) {
Copy link
Contributor

Choose a reason for hiding this comment

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

does Ctrl-A scroll to the end on iOS?

Copy link
Contributor Author

@antholeole antholeole Jun 17, 2022

Choose a reason for hiding this comment

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

This is a good call - I wasn't thinking about the keyboard on iOS world. I'd need someone else to test and verify, I Don't have access to an iOS device keyboard.

Good call, I'll ask around tomorrow.

Copy link
Contributor

Choose a reason for hiding this comment

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

Tried on simulator with "Send Keyboard Input to Device" on, it didn't scroll. On macOS it doesn't seem to scroll either (for single/multiline text fields. Only chrome scrolls to the end of the text in its omnibox).

@antholeole
Copy link
Contributor Author

antholeole commented Jun 17, 2022

is https://github.com/flutter/flutter/pull/105799/files/dcf6ce3eb645a965d0e3270d18390e64dc25565a..64e5345bb40428e7670d96aadaa5e8fb4a5fe2f3 more or less readable? There's a bunch of post-action logic in a lot of the handlers so maybe we can abstract it out so there's not switch cases everywhere. LMK

Actually scratch this, reverting. This logic is too unique.

@antholeole antholeole marked this pull request as ready for review June 23, 2022 00:47
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 👍

There are two failing tests, but they look like flutter_svg tests that I often see flake. I would guess that rebasing on master and squashing all the commits in this PR or reopening a new PR would make them pass.

@goderbauer
Copy link
Member

(triage): @antholeole can you follow up on the feedback from above so we can get this merged? Thanks!

@antholeole
Copy link
Contributor Author

Yes, sorry. Lots of momentum on loupe, been meaning to come back to this. Switching gears rn

@goderbauer
Copy link
Member

(Triage): Looks like this is failing a customer test...

@antholeole
Copy link
Contributor Author

Oopsie

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.

Renewing my LGTM 👍

@antholeole antholeole merged commit db3b141 into flutter:master Jul 29, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Jul 30, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 30, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Jul 30, 2022
camsim99 pushed a commit to camsim99/flutter that referenced this pull request Aug 10, 2022
@antholeole
Copy link
Contributor Author

antholeole commented Oct 11, 2022 via email

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 framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants