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 copy/paste when scribble enabled #31691

Merged
merged 3 commits into from
Feb 28, 2022

Conversation

justinmc
Copy link
Contributor

@justinmc justinmc commented Feb 26, 2022

The recent scribble PR (#24224) broke cmd+c and cmd+v on scribble enabled devices. The reason was this line, which seems to have been added to avoid the "[app] pasted" notification from showing up on every keystroke.

This solution returns YES when it receives a real copy/paste action and not just a key input, so copy and paste work and you won't get the notification on normal keyboard input.

Fixes flutter/flutter#98832

CC @fbcouch

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

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

@@ -866,6 +866,32 @@ - (void)testUITextInputAvoidUnnecessaryUndateEditingClientCalls {
XCTAssertEqual(updateCount, 2);
}

- (void)testCanCopyPasteWithScribbleEnabled {
if (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPad) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is probably not ok (the test will only run on iPad?). What I'm trying to do is to get IsScribbleAvailable to return true. It's a static function in FlutterTextInputPlugin. Is there a way I can mock it instead?

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 suggest not making IsScribbleAvailable a static function. I don't see a particular reason IsScribbleAvailable has to be static.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion, that worked! This is now ready for full review.

@fbcouch
Copy link
Contributor

fbcouch commented Feb 28, 2022 via email

@justinmc
Copy link
Contributor Author

I saw your comment about the native toolbar but I was never able to get it to appear while testing on the iPad. I'll keep an eye out for it but hopefully we're good.

Copy link
Contributor

@cyanglaz cyanglaz left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for the fix!

@justinmc justinmc merged commit 615a605 into flutter:main Feb 28, 2022
@justinmc justinmc deleted the scribble-copy-paste branch February 28, 2022 21:36
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 28, 2022
@@ -1048,7 +1048,7 @@ - (BOOL)canBecomeFirstResponder {
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
// When scribble is available, the FlutterTextInputView will display the native toolbar unless
// these text editing actions are disabled.
if (IsScribbleAvailable()) {
if ([self isScribbleAvailable] && sender == NULL) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@justinmc do you remember what does sender == NULL mean here?

Also can you explain more about what this is trying to do? When I remove this sender == NULL, CMD+C/V from hardware keyboard still works. So I may be missing somehting. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry I didn't document this better, I'm struggling to remember...

Are you trying this on an iPad with a hardware keyboard attached? And iOS 14+.

The relevant part of the docs for canPerformAction say:

The object calling this method. For the editing menu commands, this is the shared UIApplication object.

Looking at the original scribble PR (#24224), we seem to call performAction a bunch. Maybe it's called with no sender from some of those and/or when hardware keys are being pressed?

Are you considering removing that expression for some reason? I would test a physical iPad and Apple Pencil and hardware keyboard before at least.

Copy link
Contributor

Choose a reason for hiding this comment

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

I am not doing anything particular for this code. I was just looking into "secure paste" feature, and trying to understand the codebase.

Copy link
Contributor

Choose a reason for hiding this comment

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

interestingly i found that this function is not even called when we copy/paste. The other function in FlutterPlatformPlugin.mm is called instead. This code seems to be obsolete

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice, I'm happy to review if you want to remove it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[iOS][iPad]: Textfield not responding to CMD+C and CMD+V shortcuts using external keyboard
4 participants