mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: copy multiple text
This commit is contained in:
parent
8da6faa74b
commit
7ef053eb0d
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user