Setting the cursor bias/assoc when merging changes from collab

Assume user A and user B are collaborating on a document and user A and user B both have their cursors at position 5. Then if user B starts typing, user A’s cursor will also move.

Is there a way to set a bias when receiveTransaction is called so that user A’s cursor doesn’t move in that case. I’m looking for something similar to the assoc parameter for stepMap.map. I basically want the bias to be negative so user A’s cursor stays in the same place and doesn’t get moved by user B typing.

@marijn any suggestions on how to implement this?

When not explicitly set, the selection is updated by mapping it with a forward assoc for transactions that change the document. You could try, after calling receiveTransaction, inspect the resulting transaction, and update its selection, before dispatching it. But that’s somewhat difficult – since there may be both remote steps and local rebased steps in there, and I guess you want to map with assoc=-1 only for the remote steps, I suppose. But since the local steps should cancel themselves out (first applied in inverse, and then normally), you could try simply mapping the state’s original cursor position through transaction.mapping.map(cursorPos, -1) and create a selection from that, and see how well it works.