Y-prosemirror - Mapping a single relative position when doc changes

I’m trying to figure out how to sync a single prosemirror position between clients and have it properly propagate to all clients as the doc changes.

Let’s say I want to “callout” position 4 in the doc (its the first paragraph). I can translate that absolute position to a relative one and sync that to all clients. They’re made aware of my “call out” and can react accordingly.

Now let’s say one client adds a new paragraph above. My “callout” should now remap to position 6.

What should happen on my client when another user makes this change (isChangeOrigin true) and what should happen on that client (isChangeOrigin false) to keep everyone aware of my “callout”?

I’m going to work on a codesandbox today that illustrates this and will update here.

Sounds a lot like the normal flow with the shared user cursor positions. Haven’t dwelt too deep into its implementation but have you checked it out? Otherwise, if you are using decorations as I said in the other recent post you can get the diff which (in theory) should allow you to shift the position correctly. Haven’t tried it myself though.

If you are using marks or inline nodes the position should automatically update as the doc changes.

Hi @jamisOn,

More about relative positions here: Y.RelativePosition - Yjs Docs

You probably already found how we use relative positions in ProseMirror. There are functions in y-prosemirror that allow you to transform a relative position from & to an absolute position. The idea is that you create a relative position (which is basically pointing at a specific character in the document), then somebody can make changes to the document which will trigger a ProseMirror transaction, then you need to transform the relative position again back to an absolute position using the updated state. Relative positions will make sure that the position still points to the original character and adjusts the position accordingly to the applied change. But it is important that you recompute the absolute position on every change (local and remote ones).