diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.h b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.h index 2a6970c61b..e4fc4e4a35 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.h +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.h @@ -148,6 +148,7 @@ FLUTTER_DARWIN_EXPORT @property(nonatomic) FlutterScribbleFocusStatus scribbleFocusStatus; @property(nonatomic, strong) NSArray* selectionRects; - (void)resetScribbleInteractionStatusIfEnding; +- (BOOL)isScribbleAvailable; - (instancetype)init NS_UNAVAILABLE; + (instancetype)new NS_UNAVAILABLE; diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm index 5c27801f3a..11cae1f4c3 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm @@ -467,17 +467,6 @@ static BOOL IsSelectionRectCloserToPoint(CGPoint point, (isBelowBottomOfLine && isFartherToRight)))); } -// Checks whether Scribble features are possibly available – meaning this is an iPad running iOS -// 14 or higher. -static BOOL IsScribbleAvailable() { - if (@available(iOS 14.0, *)) { - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { - return YES; - } - } - return NO; -} - #pragma mark - FlutterTextPosition @implementation FlutterTextPosition @@ -1013,6 +1002,17 @@ static BOOL IsScribbleAvailable() { #pragma mark UIScribbleInteractionDelegate +// Checks whether Scribble features are possibly available – meaning this is an iPad running iOS +// 14 or higher. +- (BOOL)isScribbleAvailable { + if (@available(iOS 14.0, *)) { + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { + return YES; + } + } + return NO; +} + - (void)scribbleInteractionWillBeginWriting:(UIScribbleInteraction*)interaction API_AVAILABLE(ios(14.0)) { _scribbleInteractionStatus = FlutterScribbleInteractionStatusStarted; @@ -1048,7 +1048,7 @@ static BOOL IsScribbleAvailable() { - (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) { return NO; } if (action == @selector(paste:)) { @@ -2077,7 +2077,7 @@ static BOOL IsScribbleAvailable() { - (void)setEditableSizeAndTransform:(NSDictionary*)dictionary { [_activeView setEditableTransform:dictionary[@"transform"]]; - if (IsScribbleAvailable()) { + if ([_activeView isScribbleAvailable]) { // This is necessary to set up where the scribble interactable element will be. int leftIndex = 12; int topIndex = 13; diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm index d988354446..59a96565fd 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm @@ -866,6 +866,32 @@ FLUTTER_ASSERT_ARC XCTAssertEqual(updateCount, 2); } +- (void)testCanCopyPasteWithScribbleEnabled { + if (@available(iOS 14.0, *)) { + NSDictionary* config = self.mutableTemplateCopy; + [self setClientId:123 configuration:config]; + NSArray* inputFields = self.installedInputViews; + FlutterTextInputView* inputView = inputFields[0]; + + FlutterTextInputView* mockInputView = OCMPartialMock(inputView); + OCMStub([mockInputView isScribbleAvailable]).andReturn(YES); + + [mockInputView insertText:@"aaaa"]; + [mockInputView selectAll:nil]; + + XCTAssertFalse([mockInputView canPerformAction:@selector(copy:) withSender:NULL]); + XCTAssertTrue([mockInputView canPerformAction:@selector(copy:) withSender:@"sender"]); + XCTAssertFalse([mockInputView canPerformAction:@selector(paste:) withSender:NULL]); + XCTAssertFalse([mockInputView canPerformAction:@selector(paste:) withSender:@"sender"]); + + [mockInputView copy:NULL]; + XCTAssertFalse([mockInputView canPerformAction:@selector(copy:) withSender:NULL]); + XCTAssertTrue([mockInputView canPerformAction:@selector(copy:) withSender:@"sender"]); + XCTAssertFalse([mockInputView canPerformAction:@selector(paste:) withSender:NULL]); + XCTAssertTrue([mockInputView canPerformAction:@selector(paste:) withSender:@"sender"]); + } +} + - (void)testSetMarkedTextDuringScribbleDoesNotTriggerUpdateEditingClient { if (@available(iOS 14.0, *)) { FlutterTextInputView* inputView = [[FlutterTextInputView alloc] initWithOwner:textInputPlugin];