Creating Atomic replace decorations

Are there any builtin affordances for making decorations behave atomically (in which selection treats the replaced range as a single position) like there was for CM5’s atomic TextMarker option?

If not, do you have any tips on rolling my own? My current solution is to install an EditorView update listener that:

  1. runs through all the selection ranges
  2. uses DecorationSet.between() to intersect with relevant decorations
  3. Creates a new transaction to move that range of the selection.

Unfortunately, this is surprisingly complicated. When the cursor enters the range from the left, it needs to leave to the right and vice versa. Unless I’m missing something, there isn’t any builtin way to determine the direction of motion from the view update, so I’m iterating through every range of the new selection, hoping the range with the same index in the old state’s selection is the appropriate one to compare to, and then comparing heads.

Getting the interactions correct for every combination of (enters from left | enters from right | enters via click) X (point cursor | selection) X (multiple ranges) seems both fiddly and generic (to my untrained eye).

Does it seem like a good candidate for future inclusion upstream?

1 Like

My search-fu was weak, this appears to be related: Not selecting and Copying hidden characters

The idea is to use a transaction filter that notices when the selection moves to a position where it shouldn’t be, and adjusts it accordingly. At that point, you should have enough information (the previous selection) to make a good guess on which direction a given point should be moved.