diff --git a/index.html b/index.html index 20544bd..39bfded 100644 --- a/index.html +++ b/index.html @@ -12,7 +12,7 @@ -
Popravite kar želite.
Na mizo nisem položil knjigo.
+
Popravite kar želite.
Na mizo nisem položil knjigo. Popravite kar želite.
diff --git a/online-editor.js b/online-editor.js index 532d15c..7dbee7c 100644 --- a/online-editor.js +++ b/online-editor.js @@ -62,7 +62,8 @@ async function besCheckText(el) return response.json() }) .then(responseData => { - responseData.matches.sort((a, b) => a.offset < b.offset ? -1 : a.offset > b.offset ? +1 : 0) + // responseData.matches.sort((a, b) => a.offset < b.offset ? -1 : a.offset > b.offset ? +1 : 0) + responseData.matches.sort((a, b) => a.offset < b.offset ? +1 : a.offset > b.offset ? -1 : 0); responseData.matches.forEach(match => { let range = document.createRange() @@ -93,7 +94,14 @@ async function besCheckText(el) const span = document.createElement('span') span.classList.add('typo-mistake') - //range.insertNode(span) + + // Dirty hack, copied from: https://stackoverflow.com/questions/67634286/invalidstateerror-failed-to-execute-surroundcontents-on-range-the-range-ha + span.appendChild(range.extractContents()); + range.insertNode(span); + + // This is a better way to apply span elements, + // but it doesnt work when the range has partially selected a non-Text node. + // range.surroundContents(span) }) }) .catch(error => {