-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Shift tap gesture #93835
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
Shift tap gesture #93835
Conversation
|
Gold has detected about 2 new digest(s) on patchset 3. |
| /// | ||
| /// Either base or extent will be moved to the last tapped position, whichever | ||
| /// is closest. The selection will never shrink or pivot, only grow. | ||
| void expandSelection({ required SelectionChangedCause cause }) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| break; | ||
| } | ||
| } | ||
| super.onSingleTapUp(details); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm moving these removed lines into widgets/text_selection.dart to be shared with CupertinoTextField as well. There was likely a bug here that CupertinoTextField didn't support all of these different platform and PointerDevice kind distinctions. More reason that we should add support for tap actions and centralize all of this text editing logic!
|
The gold failures in the comment above seem to be non-existent. |
|
Gold has detected about 1 new digest(s) on patchset 4. |
| /// True iff the shift key on a physical keyboard is currently pressed down. | ||
| /// | ||
| /// Used for shift + tap gestures. | ||
| bool isShiftPressed = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of keeping track of the shift pressed state here is it possible to directly get that info from the keyboard service? Maybe this? https://api.flutter.dev/flutter/services/HardwareKeyboard/logicalKeysPressed.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also the public field should be read-only it seems?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I was looking for something like that, thanks! I've also gotten rid of this public isShiftPressed then.
| switch (defaultTargetPlatform) { | ||
| case TargetPlatform.iOS: | ||
| case TargetPlatform.macOS: | ||
| renderEditable.expandSelection(cause: SelectionChangedCause.tap); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the current RenderEditable interface expose a method that converts global coordinates to TextPosition? If there is then maybe we can implement expandSelection here as a private method? Eventually I think we'd like to remove all the mutating methods on RenderEditable right? So adding new mutable APIs to it increases the chance that the API removal becomes a breaking change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like yes, getPositionForPoint, and then I can set the selection with editableText.userUpdateTextEditingValue. Thanks for the suggestion, this was the biggest thing bugging me about my approach.
|
@LongCatIsLooong I've updated the PR with your suggestions and I think it's a lot cleaner. I'm going to write some tests and move this out of draft mode, but let me know if you have any other qualms. |
|
Gold has detected about 2 new digest(s) on patchset 6. |
|
Gold has detected about 2 new digest(s) on patchset 7. |
| expect(find.byType(CupertinoButton), findsNothing); | ||
| }, | ||
| ); | ||
| }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS })); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of these tests that I added specific platforms to were testing Apple-specific behavior on all platforms. Before I moved that platform switch out of TextField and into the shared TextSelectionGestureDetectorBuilder class, CupertinoTextField was incorrectly forcing all platforms to have single taps that behaved like iOS/Mac. Now taps will behave however the platform should behave regardless of what type of field is involved.
|
Gold has detected about 2 new digest(s) on patchset 9. |
… different for other platforms
|
Gold has detected about 5 new digest(s) on patchset 11. |
|
@LongCatIsLooong Ready for review. |
|
Gold has detected about 1 new digest(s) on patchset 13. |
|
Gold has detected about 2 new digest(s) on patchset 14. |
|
Golden file changes have been found for this pull request. Click here to view and triage (e.g. because this is an intentional change). If you are still iterating on this change and are not ready to resolve the images on the Flutter Gold dashboard, consider marking this PR as a draft pull request above. You will still be able to view image results on the dashboard, commenting will be silenced, and the check will not try to resolve itself until marked ready for review. For more guidance, visit Writing a golden file test for Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
…er text selection toolbar
|
@LongCatIsLooong Goldens are fixed and ready for re-review. There was a golden test that tested tapping "Select All" in the text selection toolbar on web, which isn't a thing, so I've skipped that test on web. |
LongCatIsLooong
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
| /// this callback. | ||
| @protected | ||
| void onSingleTapUp(TapUpDetails details) { | ||
| if (_isShiftTapping) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This reminds me, what happens if the user presses shift and drag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call, I didn't even think to try that. Looks like the drag should extend the selection created by the shift + tapdown. Unfortunately what Flutter does with this PR is to start a new selection when the drag starts. I'll merge this PR since it's ready to go, but I'll follow up with another one to handle the drag. I won't close the issue (#91979) until both PRs are merged.
Exploring how we can do shift + tap in the least hacky way.
Really we should have a way to do this kind of thing with actions (coming soon but not soon enough).
Partial fix for #91979
Screen.Recording.2021-11-18.at.11.14.55.AM.mov