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 cf77aff62b..a0e10c6190 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 @@ -896,6 +896,30 @@ static FlutterAutofillType autofillTypeOf(NSDictionary* configuration) { return _textInputClient != 0; } +#pragma mark - UIResponderStandardEditActions Overrides + +- (void)cut:(id)sender { + [UIPasteboard generalPasteboard].string = [self textInRange:_selectedTextRange]; + [self replaceRange:_selectedTextRange withText:@""]; +} + +- (void)copy:(id)sender { + [UIPasteboard generalPasteboard].string = [self textInRange:_selectedTextRange]; +} + +- (void)paste:(id)sender { + [self insertText:[UIPasteboard generalPasteboard].string]; +} + +- (void)delete:(id)sender { + [self replaceRange:_selectedTextRange withText:@""]; +} + +- (void)selectAll:(id)sender { + [self setSelectedTextRange:[self textRangeFromPosition:[self beginningOfDocument] + toPosition:[self endOfDocument]]]; +} + #pragma mark - UITextInput Overrides - (id)tokenizer { 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 e8a992ee0a..0112938145 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 @@ -247,6 +247,30 @@ FLUTTER_ASSERT_ARC XCTAssertEqual(substring.length, 0ul); } +- (void)testStandardEditActions { + NSDictionary* config = self.mutableTemplateCopy; + [self setClientId:123 configuration:config]; + NSArray* inputFields = self.installedInputViews; + FlutterTextInputView* inputView = inputFields[0]; + + [inputView insertText:@"aaaa"]; + [inputView selectAll:nil]; + [inputView cut:nil]; + [inputView insertText:@"bbbb"]; + [inputView paste:nil]; + [inputView selectAll:nil]; + [inputView copy:nil]; + [inputView paste:nil]; + [inputView selectAll:nil]; + [inputView delete:nil]; + [inputView paste:nil]; + [inputView paste:nil]; + + UITextRange* range = [FlutterTextRange rangeWithNSRange:NSMakeRange(0, 30)]; + NSString* substring = [inputView textInRange:range]; + XCTAssertEqualObjects(substring, @"bbbbaaaabbbbaaaa"); +} + - (void)testNoZombies { // Regression test for https://github.com/flutter/flutter/issues/62501. FlutterSecureTextInputView* passwordView = [[FlutterSecureTextInputView alloc] init];