So, sometimes I really feel like an idiot while using PM. I get away so much richer after each post on here, but I always feel like I'm wasting people's time, because most of the time my questions are so trivial. Anyway, here I am whining about wasting people's time while I waste their time explaining how I feel I'm wasting their time... let's move to the question.
Still working on implementing a custom solution for spellchecking. I've already posted about here, if you feel like checking it out. I also posted my solution at the end. So, now I've got the positions that match up with the PM document. Cool. But for the life of me, I can't get PM to replace the old (misspelled) word with the new one. I've read all the posts on here about similar issues, I've read the source code to see what replace, replaceWith, and replaceRange all do, and still no luck. Here's how I tackle the issue:
const node = schema.text(w);
const frag = Fragment.from(node);
const slice = new Slice(frag, 0, 0);
//suggestions is an array of objects describing each misspelled word and other useful properties
//editor is the active PM editor instance
const t = editor.state.tr.replaceRange(suggestions.position.from, suggestions.position.to + 1, slice);
const st = editor.state.apply(t);
I've tried other variants of this code, and all give me the same result. The misspelled word gets deleted in the new document resulting from the transaction, but the new word is not inserted. I've even tried of splitting into two steps, delete and insert. When I do that, I get two steps on the transaction object, but still no insertion.
Can anybody point me in the right direction here?