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 multi lines text
Vincent Chand28321167184
diff --git a/frontend/app_flowy/packages/flowy_editor/lib/document/node.dart b/frontend/app_flowy/packages/flowy_editor/lib/document/node.dartindex 3a7ad36456..c3f75c5c9c 100644--- a/frontend/app_flowy/packages/flowy_editor/lib/document/node.dart+++ b/frontend/app_flowy/packages/flowy_editor/lib/document/node.dart@@ -176,10 +176,11 @@ class TextNode extends Node {TextNode({required super.type,- required super.children,- required super.attributes,required Delta delta,- }) : _delta = delta;+ LinkedList<Node>? children,+ Attributes? attributes,+ }) : _delta = delta,+ super(children: children ?? LinkedList(), attributes: attributes ?? {});TextNode.empty(): _delta = Delta([TextInsert(' ')]),diff --git a/frontend/app_flowy/packages/flowy_editor/lib/infra/html_converter.dart b/frontend/app_flowy/packages/flowy_editor/lib/infra/html_converter.dartindex e1920555af..40687ca160 100644--- a/frontend/app_flowy/packages/flowy_editor/lib/infra/html_converter.dart+++ b/frontend/app_flowy/packages/flowy_editor/lib/infra/html_converter.dart@@ -1,5 +1,3 @@-import 'dart:collection';-import 'package:flowy_editor/document/node.dart';import 'package:flowy_editor/document/text_delta.dart';import 'package:html/parser.dart' show parse;@@ -20,8 +18,7 @@ class HTMLConverter {}if (delta.operations.isNotEmpty) {- result.add(TextNode(- type: "text", children: LinkedList(), attributes: {}, delta: delta));+ result.add(TextNode(type: "text", delta: delta));}return result;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 01149af9ca..ca9debb2b0 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@@ -34,7 +34,33 @@ _handlePaste(EditorState editorState) async {_pasteHTML(editorState, data.html!);return;}- debugPrint('paste ${data.text ?? ''}');+ if (data.text != null) {+ _handlePastePlainText(editorState, data.text!);+ return;+ }+}++_handlePastePlainText(EditorState editorState, String plainText) {+ final selection = editorState.cursorSelection;+ if (selection == null) {+ return;+ }++ final path = [...selection.end.path];+ if (path.isEmpty) {+ return;+ }+ path[path.length - 1]++;++ final lines =+ plainText.split("\n").map((e) => e.replaceAll(RegExp(r'\r'), ""));+ final nodes = lines+ .map((e) => TextNode(type: "text", delta: Delta().insert(e)))+ .toList();++ final tb = TransactionBuilder(editorState);+ tb.insertNodes(path, nodes);+ tb.commit();}_handleCut() {