mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: implement delete multiple text node and merge the text.
This commit is contained in:
parent
89a0a5599e
commit
b577489c2f
@ -48,6 +48,10 @@ class TransactionBuilder {
|
|||||||
add(DeleteOperation(path: node.path, removedValue: node));
|
add(DeleteOperation(path: node.path, removedValue: node));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deleteNodes(List<Node> nodes) {
|
||||||
|
nodes.forEach(deleteNode);
|
||||||
|
}
|
||||||
|
|
||||||
textEdit(TextNode node, Delta Function() f) {
|
textEdit(TextNode node, Delta Function() f) {
|
||||||
beforeSelection = state.cursorSelection;
|
beforeSelection = state.cursorSelection;
|
||||||
final path = node.path;
|
final path = node.path;
|
||||||
|
@ -57,24 +57,19 @@ FlowyKeyEventHandler deleteTextHandler = (editorState, event) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (var i = 0; i < textNodes.length; i++) {
|
final first = textNodes.first;
|
||||||
final textNode = textNodes[i];
|
var content = textNodes.last.toRawString();
|
||||||
if (i == 0) {
|
content = content.substring(selection.end.offset, content.length);
|
||||||
transactionBuilder.deleteText(
|
// Merge the fist and the last text node content,
|
||||||
textNode,
|
// and delete the all nodes expect for the first.
|
||||||
selection.start.offset,
|
transactionBuilder
|
||||||
textNode.toRawString().length - selection.start.offset,
|
..deleteNodes(textNodes.sublist(1))
|
||||||
);
|
..replaceText(
|
||||||
} else if (i == textNodes.length - 1) {
|
first,
|
||||||
transactionBuilder.deleteText(
|
selection.start.offset,
|
||||||
textNode,
|
first.toRawString().length - selection.start.offset,
|
||||||
0,
|
content,
|
||||||
selection.end.offset,
|
);
|
||||||
);
|
|
||||||
} else {
|
|
||||||
transactionBuilder.deleteNode(textNode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
transactionBuilder.commit();
|
transactionBuilder.commit();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user