Cursor jumping when using setSelection in handleClickOn event

Hi everyone,

I’m experiencing an issue with cursor behavior when handling click events in a ProseMirror plugin.

Problem: When using handleClickOn, I’m seeing an undesirable “jumping” effect where:

  1. The cursor first appears near the clicked field (default ProseMirror behavior)
  2. Then immediately jumps to my intended position when my handleClickOn code executes and sets the new selection

Any suggestion? THANKS

The browser’s native selection behavior for mouse clicks happens before the click event is fired, so that’s probably what you’re seeing. You could handle mousedown events instead, but that’ll make it a lot more awkward to distinguish between clicks and drags.

Thanks for your response. I fix it using event.preventDefault(); before the calling setSelection(selection: Selection)