Skip to content
Merged
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
48 changes: 35 additions & 13 deletions ios/editorTextView/EditorTextView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ - (void)copy:(id)sender {

UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
[pasteboard setItems:@[@{
UTTypePlainText.identifier : plainText,
UTTypeUTF8PlainText.identifier : plainText,
UTTypeHTML.identifier : escapedHtml,
UTTypeRTF.identifier : rtfData
}]];
Expand Down Expand Up @@ -58,21 +58,41 @@ - (void)paste:(id)sender {
: [typedEditor->parser insertFromHtml:initiallyProcessedHtml location:currentRange.location];
} else {
// fall back to plain text, otherwise do nothing
if([pasteboardTypes containsObject:UTTypePlainText.identifier]) {
NSString *plainString = [pasteboard valueForPasteboardType:UTTypePlainText.identifier];
currentRange.length > 0
? [TextInsertionUtils replaceText:plainString inView:typedEditor->textView at:currentRange additionalAttributes:nullptr editor:typedEditor]
: [TextInsertionUtils insertText:plainString inView:typedEditor->textView at:currentRange.location additionalAttributes:nullptr editor:typedEditor];
}
[self tryHandlingPlainTextItemsIn:pasteboard range:currentRange editor:typedEditor];
}
} else if([pasteboardTypes containsObject:UTTypePlainText.identifier]) {
// just plain text
} else {
[self tryHandlingPlainTextItemsIn:pasteboard range:currentRange editor:typedEditor];
}

[typedEditor anyTextMayHaveBeenModified];
}

- (void)tryHandlingPlainTextItemsIn:(UIPasteboard *)pasteboard range:(NSRange)range editor:(ReactNativeRichTextEditorView *)editor {
NSArray *existingTypes = pasteboard.pasteboardTypes;
NSArray *handledTypes = @[UTTypeUTF8PlainText.identifier, UTTypePlainText.identifier];
NSString *plainText;

for(NSString *type in handledTypes) {
if(![existingTypes containsObject:type]) {
continue;
}

id value = [pasteboard valueForPasteboardType:type];

if([value isKindOfClass:[NSData class]]) {
plainText = [[NSString alloc]initWithData:value encoding:NSUTF8StringEncoding];
} else if([value isKindOfClass:[NSString class]]) {
plainText = (NSString *)value;
}
}

NSString *plainString = [pasteboard valueForPasteboardType:UTTypePlainText.identifier];
currentRange.length > 0
? [TextInsertionUtils replaceText:plainString inView:typedEditor->textView at:currentRange additionalAttributes:nullptr editor:typedEditor]
: [TextInsertionUtils insertText:plainString inView:typedEditor->textView at:currentRange.location additionalAttributes:nullptr editor:typedEditor];
if(!plainText) {
return;
}

range.length > 0
? [TextInsertionUtils replaceText:plainText inView:editor->textView at:range additionalAttributes:nullptr editor:editor]
: [TextInsertionUtils insertText:plainText inView:editor->textView at:range.location additionalAttributes:nullptr editor:editor];
}

- (void)cut:(id)sender {
Expand All @@ -81,6 +101,8 @@ - (void)cut:(id)sender {

[self copy:sender];
[TextInsertionUtils replaceText:@"" inView:typedEditor->textView at:typedEditor->textView.selectedRange additionalAttributes:nullptr editor:typedEditor];

[typedEditor anyTextMayHaveBeenModified];
}

@end
Loading