Skip to content

Commit

Permalink
[iOS] Hardware keyboard text editing shortcuts (flutter#28971)
Browse files Browse the repository at this point in the history
Disallow pasting non-text into FlutterTextInputPlugin (flutter#29374)
  • Loading branch information
yx-mike committed Dec 31, 2021
1 parent ebb669f commit 021c382
Showing 1 changed file with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,42 @@ - (BOOL)canBecomeFirstResponder {
return _textInputClient != 0;
}

- (BOOL)canPerformAction:(SEL)action withSender:(nullable id)sender {
if (action == @selector(paste:)) {
// Forbid pasting images, memojis, or other non-string content.
return [UIPasteboard generalPasteboard].string != nil;
}

return [super canPerformAction:action withSender:sender];
}

#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 {
NSString* pasteboardString = [UIPasteboard generalPasteboard].string;
if (pasteboardString != nil) {
[self insertText:pasteboardString];
}
}

- (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

0 comments on commit 021c382

Please sign in to comment.