Mapping positions in deleted nodes

So hey, Mapping is pretty cool in preventing mind-bending offset calculations. However, as it has probably come up before, you can’t replace a node (of same type) and expect the mapping to correctly point inside the new node - it will treat it deleted and point to the end of the new node.

What’s the best solution/hack to remedy this? I want my old TextSelection to behave as nothing weird had happened but I can’t really map it by any built-in mechanism. Minus the original pos by findDiffStart and use that as an offset? Dont work though when you encounter first added/deleted node.

If you replaced the context it exists in, I don’t see how pretending nothing has happened is an option. The content it used to point at is no longer in the document, so those positions have no meaning anymore. If you are replacing something with another thing that has the same content, try using ReplaceAroundSteps to make the change—those preserve positions in the unchanged content.

Hmm okay, I’ll see if I can use that. Also this reminded me of prosemirror-changeset and how it diffs pretty perfectly the added and deleted content from transaction steps. It just would be so much easier if I didn’t have to manually check every node and see whether to insert, delete or replace.