Skip to content

moving the left handle automatically scrolls EditableText to the right handle, which doesn't happen on native - #105836

Merged
justinmc merged 9 commits into
flutter:masterfrom
takassh:text_selection_toolbar_handle
Mar 1, 2023
Merged

justinmc merged 9 commits into
flutter:masterfrom
takassh:text_selection_toolbar_handle

Conversation

@takassh

@takassh takassh commented Jun 11, 2022 •

Copy link
Copy Markdown
Contributor

fixes #105821

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.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard flutter-dashboard Bot added a: text input Entering text in a text field or keyboard related problems p: cupertino_ui cupertino_ui package in flutter/packages p: material_ui material_ui package in flutter/packages framework flutter/packages/flutter repository. See also f: labels. labels Jun 11, 2022
@takassh
takassh marked this pull request as ready for review June 13, 2022 10:18
@takassh

takassh commented Jun 17, 2022

Copy link
Copy Markdown
Contributor Author

cc @chunhtai

@takassh

takassh commented Jun 22, 2022

Copy link
Copy Markdown
Contributor Author

@justinmc @chunhtai
any updates?

@justinmc
justinmc self-requested a review June 22, 2022 16:55

@justinmc justinmc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for fixing this!

My main concern at this point is just that the isEnd parameter in methods like _handleSelectionChanged isn't very clear at first glance. It makes sense in _handleSelectionHandleChanged to describe which handle changed, but elsewhere it's not clear what it means.

Maybe it's just the naming that needs to change. You could call it handleToView and set it to an enum, either baseHandle or extentHandle. Something like that?

CC @antholeole who I think was looking at a somewhat similar issue.

Comment thread packages/flutter/lib/src/material/selectable_text.dart Outdated
Comment thread packages/flutter/lib/src/material/text_field.dart Outdated
Comment thread packages/flutter/lib/src/widgets/editable_text.dart Outdated
Comment thread packages/flutter/lib/src/widgets/text_selection.dart Outdated
Comment thread packages/flutter/lib/src/widgets/text_selection.dart Outdated
Comment thread packages/flutter/test/cupertino/text_field_test.dart Outdated
Comment thread packages/flutter/test/cupertino/text_field_test.dart Outdated
Comment thread packages/flutter/test/cupertino/text_field_test.dart Outdated
Comment thread packages/flutter/test/cupertino/text_field_test.dart Outdated
@antholeole

Copy link
Copy Markdown
Contributor

This whole comment assumes that there's no way to drag the right handle without it already being in view. If that's a wrong assumption, then disregard :).

I wonder if this is the correct solution for this problem... The reason why this is not a problem for the second selection handle is that the call to selectionDelegate.bringIntoView in _handleSelectionHandleChanged always does nothing since dragging the second selection handle means the end of the selection extent is already in view. It gets called for both left and right handles, but never ever does anything for the right handle.

if we know that it shouldn't be called when dragging the left handle, and never does anything when dragging the right handle - do we need this call at all? Can't we just delete it and all is well?

@takassh

takassh commented Jun 23, 2022

Copy link
Copy Markdown
Contributor Author

@justinmc
thank you for review :) I fixed it based on your review.
but I'm not sure where I should write enum. Where is the most optimal location to write enum?

@takassh

takassh commented Jun 23, 2022

Copy link
Copy Markdown
Contributor Author

@antholeole
thank you for your comments!
Why doesbringIntoView exist there originally? actually, I can remove the line and it passed all tests in my local...

@takassh

takassh commented Jun 23, 2022

Copy link
Copy Markdown
Contributor Author

@justinmc
and I think this issue is mainly on mobile, so I changed TargetPlatformVariant.all() to TargetPlatformVariant.mobile() in tests

@justinmc

Copy link
Copy Markdown
Contributor

If we go with @antholeole's approach, can we get rid of the idea of isEnd altogether? That would make things really simple.

@antholeole

Copy link
Copy Markdown
Contributor

@antholeole thank you for your comments! Why doesbringIntoView exist there originally? actually, I can remove the line and it passed all tests in my local...

@takassh It was an old implementation of edge scrolling, I think. Edge scrolling was moved elsewhere, but this line was overlooked. I think it is the sole culprit of #105821 . When you said "passes all tests" are you including the tests you wrote for this PR? If so, I think it would be best (i.e. smallest footprint) if this PR was just deleting that line, and the tests you wrote.

@takassh

takassh commented Jun 23, 2022 •

Copy link
Copy Markdown
Contributor Author

@justinmc @antholeole
I see. thank you.
yeah, I said I could remove selectionDelegate.bringIntoView in _handleSelectionHandleChanged only when there is my fix.
however, we can't remove other bringIntoView to pass tests. e.g. _editableText?.bringIntoView in _handleSelectionChanged.

it seems selectionDelegate.userUpdateTextEditingValue in _handleSelectionHandleChanged internally calls other bringIntoView also. (in short , as a result, _handleSelectionHandleChanged is calling bringIntoView two times now)
therefore, anyway I think we need some flag like isEnd to tell which handle is dragged now.

@antholeole

antholeole commented Jun 23, 2022 •

Copy link
Copy Markdown
Contributor

@takassh So, just to be clear, when you remove the line that I mentioned, #105821 still happens? I removed that line and this is the behavior I get:

Screen.Recording.2022-06-22.at.4.17.03.PM.1.mov

It looks like it fixes the problem for me, unless I'm testing wrong.

EDIT: Oh I see, it's behind a platform switch flag. Let me take another look, you may be right!

@antholeole

Copy link
Copy Markdown
Contributor

Looks like you're right! The further calls are needed on platforms not iOS / macOS. thanks for this!

@takassh

takassh commented Jun 24, 2022

Copy link
Copy Markdown
Contributor Author

@antholeole

So, just to be clear, when you remove the line that I mentioned, #105821 still happens?

yes

@justinmc
so I think we need the enum. where should I write enum definition?

@antholeole

Copy link
Copy Markdown
Contributor

@justinmc what about changing ‘SelectionChangedCause.drag’ to something like SelectionChangedCause.dragLeftHandle and SelectionChangedCause.dragRightHandle?

Just a thought!

@flutter-dashboard

Copy link
Copy Markdown

This pull request executed golden file tests, but it has not been updated in a while (20+ days). Test results from Gold expire after as many days, so this pull request will need to be updated with a fresh commit in order to get results from Gold.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@takassh

takassh commented Jul 19, 2022

Copy link
Copy Markdown
Contributor Author

@justinmc
any updates?
Is there anything I can do?

@antholeole

antholeole commented Jul 19, 2022 •

Copy link
Copy Markdown
Contributor

@takassh I'll be taking over the review on this one :) sorry about the slowness, I'll get this reviewed asap. It looks almost done though, good job!

@antholeole
antholeole self-requested a review July 19, 2022 20:40

@antholeole antholeole left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we replace all instances of "IsEnd" with something like TextSelectionHandle? This will make maintinance easier in the long run. isEnd unfortunately does not feel verbose enough.

@antholeole

antholeole commented Jul 19, 2022 •

Copy link
Copy Markdown
Contributor

Something like this:

diff --git a/packages/flutter/lib/src/widgets/text_selection.dart b/packages/flutter/lib/src/widgets/text_selection.dart
index 30f96187ba..e59d176fd9 100644
--- a/packages/flutter/lib/src/widgets/text_selection.dart
+++ b/packages/flutter/lib/src/widgets/text_selection.dart
@@ -2286,6 +2286,11 @@ class ClipboardStatusNotifier extends ValueNotifier<ClipboardStatus> with Widget
   }
 }
 
+enum TextSelectionHandleSide {
+  BaseHandle,
+  ExtentHandle
+}
+
 /// An enumeration of the status of the content on the user's clipboard.
 enum ClipboardStatus {
   /// The clipboard content can be pasted, such as a String of nonzero length.

@takassh

takassh commented Jul 20, 2022

Copy link
Copy Markdown
Contributor Author

@antholeole
thank you for reviewing!
I fixed bool IsEnd to TextSelectionDraggedHandleSide handleSide.

however, I encountered following CI failure, and it seems not to be my failure, because I didn't touch about flutter_logo in this PR.

| Warning - golden differed less than .06% (0.006202083333333334%), ignoring failure but producing output
| Golden "golden_widget/flutter_logo.string.color_filter.png": Pixel test failed, 0.62% diff detected.
| Failure feedback can be found at /b/s/w/ir/x/t/flutter_customer_testing.flutter_svg.DAWBDP/tests/test/failures
...
| Warning - golden differed less than .06% (0.008170833333333334%), ignoring failure but producing output
| Golden "golden_widget/flutter_logo.string.color_filter.blendmode_color.png": Pixel test failed, 0.82% diff detected.
| Failure feedback can be found at /b/s/w/ir/x/t/flutter_customer_testing.flutter_svg.DAWBDP/tests/test/failures

Could you check the CI failure?

@antholeole antholeole left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Overall, looks good! Thanks for making the changes. @justinmc might have some more nits but after you make my changes you get my approval stamp :)

I re-ran CI, hopefully it passes. I've had the same failure on my PR's, seems the test is flaky.

Comment thread packages/flutter/lib/src/cupertino/text_field.dart Outdated
Comment thread packages/flutter/lib/src/services/text_input.dart Outdated
Comment thread packages/flutter/lib/src/services/text_input.dart Outdated
Comment thread packages/flutter/lib/src/widgets/text_selection.dart Outdated
Comment thread packages/flutter/test/cupertino/text_field_test.dart Outdated
Comment thread packages/flutter/test/cupertino/text_field_test.dart Outdated
Comment thread packages/flutter/test/cupertino/text_field_test.dart Outdated
Comment thread packages/flutter/test/cupertino/text_field_test.dart Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why mobile?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Currently I think the mobile text selection handles will appear for touch events on desktop platforms, and if so then this test would be valid on all platforms.

Long term this will be cleaned up: #106586. But for now I think this is ok as long as it passes and as long as we're consistent with the variant on all the relevant tests in this PR.

@takassh

takassh commented Jul 20, 2022

Copy link
Copy Markdown
Contributor Author

@antholeole
wow, thank you for quick review!!

Code was changed based on your comment without #105836 (comment)

antholeole
antholeole previously approved these changes Jul 21, 2022

@antholeole antholeole left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM! Thanks for being patient with this one, I know it had a ton of rounds.

I'm going to wait for Justin to sign off on it since he's worked a ton more with this code, but I think this is looking good.

# Conflicts:
#	packages/flutter/lib/src/cupertino/text_field.dart
#	packages/flutter/lib/src/material/text_field.dart
#	packages/flutter/lib/src/widgets/text_selection.dart
#	packages/flutter/test/material/text_field_test.dart
@takassh
takassh force-pushed the text_selection_toolbar_handle branch from aa01042 to beb3b0f Compare March 1, 2023 08:20
@takassh

takassh commented Mar 1, 2023

Copy link
Copy Markdown
Contributor Author

@justinmc
hi 👋 long time to see you!
I updated from your new comments and my pr was synched with the latest master branch.

@justinmc
justinmc merged commit 909e29e into flutter:master Mar 1, 2023
@justinmc

justinmc commented Mar 1, 2023

Copy link
Copy Markdown
Contributor

Thanks for the quick response, merged!

engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 2, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 2, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 2, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 2, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 2, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 2, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 2, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 3, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 3, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 10, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 10, 2023
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. p: cupertino_ui cupertino_ui package in flutter/packages p: material_ui material_ui package in flutter/packages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

When SelectionEndHandle is hidden and SelectionStartHandle is changed, the view goes to SelectionEndHandle.

3 participants