mirror of
https://github.com/AppFlowy-IO/AppFlowy
synced 2026-05-24 09:38:25 +00:00
fix: open-ai replace does not work on certain use-cases
This commit is contained in:
parent
8cc3eb4846
commit
f02fcda8c0
1 changed files with 23 additions and 7 deletions
|
|
@ -371,6 +371,14 @@ extension TextTransaction on Transaction {
|
||||||
|
|
||||||
if (textNodes.length < texts.length) {
|
if (textNodes.length < texts.length) {
|
||||||
final length = texts.length;
|
final length = texts.length;
|
||||||
|
var path = textNodes.first.path;
|
||||||
|
|
||||||
|
//FIND OFFSET CHARACTERS AFTER SELECTION
|
||||||
|
String offSetChar =
|
||||||
|
(document.nodeAtPath(selection.end.path) as TextNode)
|
||||||
|
.toPlainText()
|
||||||
|
.substring(selection.end.offset);
|
||||||
|
|
||||||
for (var i = 0; i < texts.length; i++) {
|
for (var i = 0; i < texts.length; i++) {
|
||||||
final text = texts[i];
|
final text = texts[i];
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
|
|
@ -380,7 +388,7 @@ extension TextTransaction on Transaction {
|
||||||
textNodes.first.toPlainText().length,
|
textNodes.first.toPlainText().length,
|
||||||
text,
|
text,
|
||||||
);
|
);
|
||||||
} else if (i == length - 1) {
|
} else if (i == length - 1 && textNodes.length >= 2) {
|
||||||
replaceText(
|
replaceText(
|
||||||
textNodes.last,
|
textNodes.last,
|
||||||
0,
|
0,
|
||||||
|
|
@ -396,15 +404,23 @@ extension TextTransaction on Transaction {
|
||||||
text,
|
text,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
var path = textNodes.first.path;
|
if (i == texts.length - 1) {
|
||||||
var j = i - textNodes.length + length - 1;
|
//ADD OFFSET CHARACTER TO END OF LAST TEXT-NODE TO AVOID DATA LOSS
|
||||||
while (j > 0) {
|
document.insert(path, [
|
||||||
path = path.next;
|
TextNode(
|
||||||
j--;
|
delta: Delta()..insert("${text}${offSetChar}"),
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
document.insert(path, [
|
||||||
|
TextNode(
|
||||||
|
delta: Delta()..insert(text),
|
||||||
|
),
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
insertNode(path, TextNode(delta: Delta()..insert(text)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
path = path.next;
|
||||||
}
|
}
|
||||||
afterSelection = null;
|
afterSelection = null;
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue