Skip to content

Conversation

@justinmc
Copy link
Contributor

@justinmc justinmc commented Nov 18, 2021

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

@justinmc justinmc self-assigned this Nov 18, 2021
@flutter-dashboard flutter-dashboard bot added a: text input Entering text in a text field or keyboard related problems f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Nov 18, 2021
@google-cla google-cla bot added the cla: yes label Nov 18, 2021
@skia-gold
Copy link

Gold has detected about 2 new digest(s) on patchset 3.
View them at https://flutter-gold.skia.org/cl/github/93835

///
/// 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 }) {
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 realized that the expand behavior from Mac has disappeared with #90684. I filed this issue to track that #93883.

Ideally the actions code in EditableTextState could share this logic, but I guess that won't be possible until we can do tap-based actions.

break;
}
}
super.onSingleTapUp(details);
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'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!

@justinmc
Copy link
Contributor Author

The gold failures in the comment above seem to be non-existent.

@skia-gold
Copy link

Gold has detected about 1 new digest(s) on patchset 4.
View them at https://flutter-gold.skia.org/cl/github/93835

/// True iff the shift key on a physical keyboard is currently pressed down.
///
/// Used for shift + tap gestures.
bool isShiftPressed = false;
Copy link
Contributor

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

Copy link
Contributor

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?

Copy link
Contributor Author

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

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.

Copy link
Contributor Author

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.

@justinmc
Copy link
Contributor Author

@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.

@skia-gold
Copy link

Gold has detected about 2 new digest(s) on patchset 6.
View them at https://flutter-gold.skia.org/cl/github/93835

@skia-gold
Copy link

Gold has detected about 2 new digest(s) on patchset 7.
View them at https://flutter-gold.skia.org/cl/github/93835

expect(find.byType(CupertinoButton), findsNothing);
},
);
}, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
Copy link
Contributor Author

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.

@justinmc justinmc changed the title (WIP) Shift tap gesture Shift tap gesture Nov 20, 2021
@flutter-dashboard flutter-dashboard bot added the f: cupertino flutter/packages/flutter/cupertino repository label Nov 20, 2021
@skia-gold
Copy link

Gold has detected about 2 new digest(s) on patchset 9.
View them at https://flutter-gold.skia.org/cl/github/93835

@skia-gold
Copy link

Gold has detected about 5 new digest(s) on patchset 11.
View them at https://flutter-gold.skia.org/cl/github/93835

@justinmc justinmc marked this pull request as ready for review December 4, 2021 00:53
@justinmc
Copy link
Contributor Author

justinmc commented Dec 4, 2021

@LongCatIsLooong Ready for review.

@skia-gold
Copy link

Gold has detected about 1 new digest(s) on patchset 13.
View them at https://flutter-gold.skia.org/cl/github/93835

@skia-gold
Copy link

Gold has detected about 2 new digest(s) on patchset 14.
View them at https://flutter-gold.skia.org/cl/github/93835

@flutter-dashboard
Copy link

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 package:flutter.

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

Changes reported for pull request #93835 at sha 7ec9165

@flutter-dashboard flutter-dashboard bot added the will affect goldens Changes to golden files label Dec 7, 2021
@justinmc
Copy link
Contributor Author

justinmc commented Dec 8, 2021

@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.

Copy link
Contributor

@LongCatIsLooong LongCatIsLooong left a 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) {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

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: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. will affect goldens Changes to golden files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants