Replace works like a charm but it has a curious side effect. At the end of each line, if I add a regular space, the cursor goes back to the beginning of the editor and space is erased.
with replaceWhitespace being an helper function I described above.
I play around a lot to understand what’s happening and I’m confused. I removed everything related to “replace white space” and the cursor still goes back to the beginning of the editor after I hit the space bar.
And this small line replace(/ $/g, '\xa0') in the replace function fixing this.
You really don’t want to be changing the text in your toDOM function. That text will be read from the DOM again when it changes, so your modified text will end up in the document.