Skip to content

Commit

Permalink
[iOS] Hardware keyboard text editing shortcuts (flutter#28971)
Browse files Browse the repository at this point in the history
* [iOS] Hardware keyboard text editing shortcuts

* Remove useless declarations
  • Loading branch information
moffatman authored Oct 14, 2021
1 parent 0b686f7 commit 53e4bd3
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,30 @@ - (BOOL)canBecomeFirstResponder {
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<UITextInputTokenizer>)tokenizer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,30 @@ - (void)testTextInRange {
XCTAssertEqual(substring.length, 0ul);
}

- (void)testStandardEditActions {
NSDictionary* config = self.mutableTemplateCopy;
[self setClientId:123 configuration:config];
NSArray<FlutterTextInputView*>* 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];
Expand Down

0 comments on commit 53e4bd3

Please sign in to comment.