mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: refactor the text editing code
This commit is contained in:
parent
159fe63575
commit
5ecfc4ff2e
@ -53,7 +53,7 @@ class TransactionBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
textEdit(TextNode node, Delta Function() f) {
|
textEdit(TextNode node, Delta Function() f) {
|
||||||
beforeSelection = state.cursorSelection;
|
beforeSelection = state.service.selectionService.currentSelection;
|
||||||
final path = node.path;
|
final path = node.path;
|
||||||
|
|
||||||
final delta = f();
|
final delta = f();
|
||||||
@ -91,6 +91,7 @@ class TransactionBuilder {
|
|||||||
|
|
||||||
formatText(TextNode node, int index, int length, Attributes attributes) {
|
formatText(TextNode node, int index, int length, Attributes attributes) {
|
||||||
textEdit(node, () => Delta().retain(index).retain(length, attributes));
|
textEdit(node, () => Delta().retain(index).retain(length, attributes));
|
||||||
|
afterSelection = beforeSelection;
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteText(TextNode node, int index, int length) {
|
deleteText(TextNode node, int index, int length) {
|
||||||
|
@ -17,66 +17,29 @@ bool formatRichTextStyle(
|
|||||||
// 1. All nodes are text nodes.
|
// 1. All nodes are text nodes.
|
||||||
// 2. The first node is not TextNode.
|
// 2. The first node is not TextNode.
|
||||||
// 3. The last node is not TextNode.
|
// 3. The last node is not TextNode.
|
||||||
if (textNodes.length == nodes.length) {
|
for (var i = 0; i < textNodes.length; i++) {
|
||||||
if (textNodes.length == 1) {
|
final textNode = textNodes[i];
|
||||||
|
if (i == 0 && textNode == nodes.first) {
|
||||||
builder.formatText(
|
builder.formatText(
|
||||||
textNodes.first,
|
textNode,
|
||||||
selection.start.offset,
|
selection.start.offset,
|
||||||
selection.end.offset - selection.start.offset,
|
textNode.toRawString().length - selection.start.offset,
|
||||||
|
attributes,
|
||||||
|
);
|
||||||
|
} else if (i == textNodes.length - 1 && textNode == nodes.last) {
|
||||||
|
builder.formatText(
|
||||||
|
textNode,
|
||||||
|
0,
|
||||||
|
selection.end.offset,
|
||||||
attributes,
|
attributes,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
for (var i = 0; i < textNodes.length; i++) {
|
builder.formatText(
|
||||||
final node = textNodes[i];
|
textNode,
|
||||||
if (i == 0) {
|
0,
|
||||||
builder.formatText(
|
textNode.toRawString().length,
|
||||||
node,
|
attributes,
|
||||||
selection.start.offset,
|
);
|
||||||
node.toRawString().length - selection.start.offset,
|
|
||||||
attributes,
|
|
||||||
);
|
|
||||||
} else if (i == textNodes.length - 1) {
|
|
||||||
builder.formatText(
|
|
||||||
node,
|
|
||||||
0,
|
|
||||||
selection.end.offset,
|
|
||||||
attributes,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
builder.formatText(
|
|
||||||
node,
|
|
||||||
0,
|
|
||||||
node.toRawString().length,
|
|
||||||
attributes,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (var i = 0; i < textNodes.length; i++) {
|
|
||||||
final node = textNodes[i];
|
|
||||||
if (i == 0 && node == nodes.first) {
|
|
||||||
builder.formatText(
|
|
||||||
node,
|
|
||||||
selection.start.offset,
|
|
||||||
node.toRawString().length - selection.start.offset,
|
|
||||||
attributes,
|
|
||||||
);
|
|
||||||
} else if (i == textNodes.length - 1 && node == nodes.last) {
|
|
||||||
builder.formatText(
|
|
||||||
node,
|
|
||||||
0,
|
|
||||||
selection.end.offset,
|
|
||||||
attributes,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
builder.formatText(
|
|
||||||
node,
|
|
||||||
0,
|
|
||||||
node.toRawString().length,
|
|
||||||
attributes,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user