From d90414a8c117e235a764d0996dd8ce3f0598943d Mon Sep 17 00:00:00 2001 From: "Lucas.Xu" Date: Tue, 18 Oct 2022 19:22:09 +0800 Subject: [PATCH] fix: could not copy and paste the plain text --- .../copy_paste_handler.dart | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/copy_paste_handler.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/copy_paste_handler.dart index d494859957..63aa61925f 100644 --- a/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/copy_paste_handler.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/copy_paste_handler.dart @@ -39,7 +39,10 @@ void _handleCopy(EditorState editorState) async { endOffset: selection.end.offset) .toHTMLString(); Log.keyboard.debug('copy html: $htmlString'); - RichClipboard.setData(RichClipboardData(html: htmlString)); + RichClipboard.setData(RichClipboardData( + html: htmlString, + text: textNode.toPlainText(), + )); } else { Log.keyboard.debug('unimplemented: copy non-text'); } @@ -55,13 +58,15 @@ void _handleCopy(EditorState editorState) async { endNode: endNode, ).toList(); - final copyString = NodesToHTMLConverter( - nodes: nodes, - startOffset: selection.start.offset, - endOffset: selection.end.offset) - .toHTMLString(); - Log.keyboard.debug('copy html: $copyString'); - RichClipboard.setData(RichClipboardData(html: copyString)); + final html = NodesToHTMLConverter( + nodes: nodes, + startOffset: selection.start.offset, + endOffset: selection.end.offset, + ).toHTMLString(); + final text = nodes + .map((node) => node is TextNode ? node.toPlainText() : '\n') + .join('\n'); + RichClipboard.setData(RichClipboardData(html: html, text: text)); } void _pasteHTML(EditorState editorState, String html) {