Skip to content

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.

feat: copy multiple text

Vincent Chan7ef053eb0d64
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.dart
index f413801771..a79c121684 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
@@ -1,6 +1,7 @@
import 'package:flowy_editor/flowy_editor.dart';
import 'package:flowy_editor/service/keyboard_service.dart';
import 'package:flowy_editor/infra/html_converter.dart';
+import 'package:flowy_editor/document/node_traverser.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:rich_clipboard/rich_clipboard.dart';
@@ -25,7 +26,37 @@ _handleCopy(EditorState editorState) async {
}
return;
}
- debugPrint('copy');
+
+ final beginNode = editorState.document.nodeAtPath(selection.start.path)!;
+ final endNode = editorState.document.nodeAtPath(selection.end.path)!;
+ final traverser = NodeTraverser(editorState.document, beginNode);
+
+ var copyString = "";
+ while (traverser.currentNode != null) {
+ final node = traverser.next()!;
+ if (node.type == "text") {
+ final textNode = node as TextNode;
+ if (node == beginNode) {
+ final htmlString =
+ deltaToHtml(textNode.delta.slice(selection.start.offset));
+ copyString += htmlString;
+ } else if (node == endNode) {
+ final htmlString =
+ deltaToHtml(textNode.delta.slice(0, selection.end.offset));
+ copyString += htmlString;
+ } else {
+ final htmlString = deltaToHtml(textNode.delta);
+ copyString += htmlString;
+ }
+ }
+ // TODO: handle image and other blocks
+
+ if (node == endNode) {
+ break;
+ }
+ }
+ debugPrint('copy html: $copyString');
+ RichClipboard.setData(RichClipboardData(html: copyString));
}
_pasteHTML(EditorState editorState, String html) {