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

[iOS] Hardware keyboard text editing shortcuts #28971

Merged
merged 2 commits into from
Oct 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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];
moffatman marked this conversation as resolved.
Show resolved Hide resolved

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