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 25f52c6914..9ab74cdb14 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 @@ -41,7 +41,10 @@ void _handleCopy(EditorState editorState) async { Log.keyboard.debug('copy html: $htmlString'); RichClipboard.setData(RichClipboardData( html: htmlString, - text: textNode.toPlainText(), + text: textNode.toPlainText().substring( + selection.startIndex, + selection.endIndex, + ), )); } else { Log.keyboard.debug('unimplemented: copy non-text'); @@ -63,9 +66,19 @@ void _handleCopy(EditorState editorState) async { startOffset: selection.start.offset, endOffset: selection.end.offset, ).toHTMLString(); - final text = nodes - .map((node) => node is TextNode ? node.toPlainText() : '\n') - .join('\n'); + var text = ''; + for (final node in nodes) { + if (node is TextNode) { + if (node.path == selection.start.path) { + text += node.toPlainText().substring(selection.start.offset); + } else if (node.path == selection.end.path) { + text += node.toPlainText().substring(0, selection.end.offset); + } else { + text += node.toPlainText(); + } + } + text += '\n'; + } RichClipboard.setData(RichClipboardData(html: html, text: text)); }