Set Cursor when Clicking on Decoration.replace()

Hi,

I have a View Plugin that uses Decoration.replace() to replace parts of the document with a <span>. When I use the keyboard to move the cursor inside the replaced range, the original text in that range is shown (as intended). I would like to be able to move the cursor to the beginning of the range when clicking on that <span> . What would be the best way to archive that?

Naively, I would just register an on-click listener and then move the cursor. But I guess there is a better way…

By the way, Codemirror Next feels great and it’s amazing that I was able to come up with a working LaTex-Formula-Plugin in a matter of two hours - without ever using Codemirror Next before.

A handler on the span element would work, but I think an editor-wide handler that checks if event.target is in such a span and uses posAtDOM to find the span’s start position when it is would be a bit nicer.