mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: paste multi lines text
This commit is contained in:
parent
40c3f07be4
commit
d283211671
@ -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(' ')]),
|
||||
|
@ -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;
|
||||
|
@ -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() {
|
||||
|
Loading…
Reference in New Issue
Block a user