Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
feat: paste text inside text
Vincent Chan290435b0eea0
diff --git a/frontend/app_flowy/packages/flowy_editor/lib/service/internal_key_event_handlers/copy_paste_handler.dart b/frontend/app_flowy/packages/flowy_editor/lib/service/internal_key_event_handlers/copy_paste_handler.dartindex d7eda6b64a..6e6e30dbf4 100644--- a/frontend/app_flowy/packages/flowy_editor/lib/service/internal_key_event_handlers/copy_paste_handler.dart+++ b/frontend/app_flowy/packages/flowy_editor/lib/service/internal_key_event_handlers/copy_paste_handler.dart@@ -37,12 +37,47 @@ _pasteHTML(EditorState editorState, String html) {() => Delta().retain(startOffset).concat(firstTextNode.delta));tb.setAfterSelection(Selection.collapsed(Position(path: path, offset: startOffset + firstTextNode.delta.length)));+ tb.commit();}+ }++ _pasteMultipleLinesInText(editorState, path, selection.start.offset, nodes);+}++_pasteMultipleLinesInText(+ EditorState editorState, List<int> path, int offset, List<Node> nodes) {+ final tb = TransactionBuilder(editorState);++ final firstNode = nodes[0];+ final nodeAtPath = editorState.document.nodeAtPath(path)!;++ if (nodeAtPath.type == "text" && firstNode.type == "text") {+ // split and merge+ final textNodeAtPath = nodeAtPath as TextNode;+ final firstTextNode = firstNode as TextNode;+ final remain = textNodeAtPath.delta.slice(offset);++ tb.textEdit(+ textNodeAtPath,+ () => Delta()+ .retain(offset)+ .delete(remain.length)+ .concat(firstTextNode.delta));++ path[path.length - 1]++;+ final tailNodes = nodes.sublist(1);+ if (tailNodes.last.type == "text") {+ final tailTextNode = tailNodes.last as TextNode;+ tailTextNode.delta = tailTextNode.delta.concat(remain);+ } else if (remain.length > 0) {+ tailNodes.add(TextNode(type: "text", delta: remain));+ }++ tb.insertNodes(path, tailNodes);tb.commit();return;}- final tb = TransactionBuilder(editorState);path[path.length - 1]++;tb.insertNodes(path, nodes);tb.commit();