function generateOperations2(
text,
updateText
) {
const m = text.length;
const n = updateText.length;
const lcs = lcsFunctions.findLCS(text, updateText);
const ops = [];
const removeOps = [];
let i = 0,
j = 0;
let curPos = 0;
for (const char of lcs) {
while (text[i] !== char) {
removeOps.push({
type: "remove_text",
offset: curPos,
text: text[i],
path: [],
});
i++;
curPos ++;
}
while (updateText[j] !== char) {
ops.push({
type: "insert_text",
offset: curPos,
text: updateText[j],
path: [],
});
j++;
curPos++;
}
i++;
j++;
curPos++;
}
while (i < m) {
removeOps.push({ type: "remove_text", offset: curPos, text: text[i], path: [] });
i++;
curPos++;
}
while (j < n) {
ops.push({ type: "insert_text", offset: curPos, text: updateText[j], path: [] });
j++;
curPos++;
}
return ops.concat(removeOps.reverse());
}