updateTipTap = function(editor, paragraphIndex, targetTextStr){
let textTemplate = Object({
type: "text",
text: ""
})
let textTemplateBold = Object({
type: "text",
text: "",
marks: [{"type": "bold"}]
})
let delay = 200;
let totalTextObject = editor.getJSON()
let currentTextStr = totalTextObject.content[paragraphIndex].content.map(obj => obj.text).join("");
let nwResult = nw(currentTextStr, targetTextStr, mispen, gappen, skwpen)
let tmpTextObjArray = nwResult.aout.map(word => {
const textObj = { ...textTemplate };
textObj.text = word;
return textObj;
});
updateEditor(editor, tmpTextObjArray, paragraphIndex)
let i = 0;
const iterations = nwResult.summary.length;
function loopIteration() {
if (i < iterations) {
const operation = nwResult.summary[i]
switch (operation) {
case "=":
break;
case "^":
if (nwResult.aout[i] === '^') {
tmpTextObjArray[i].text = nwResult.bout[i]
tmpTextObjArray[i].marks = [{"type": "bold"}]
}
else {
tmpTextObjArray[i].text = "^"
}
break;
case "!":
tmpTextObjArray[i].text = nwResult.bout[i]
tmpTextObjArray[i].marks = [{"type": "bold"}]
break;
}
updateEditor(editor, tmpTextObjArray, paragraphIndex)
console.log(`Iteration ${i + 1}`, tmpTextObjArray, nwResult.summary);
i = findNext(nwResult.summary, i)
if (i < iterations) {
setTimeout(loopIteration, delay);
}
}
}
loopIteration();
return totalTextObject
}