Overriding ProseMirror's TextSelection internally?

I understand that custom Selection types are supported, but it’s not clear to me how to actually make use of those outside of very specific cases because so much relies on TextSelection internally.

I noticed the code mentions that custom bookmarks can make custom selections play nicely with prosemirror-history (prosemirror-state/src/selection.ts at master · ProseMirror/prosemirror-state · GitHub) but it’s not clear to me how we’d actually make use of the custom selection and its bookmarks.

If I make and use CustomSelection, I noticed when I undo that the selection is back to TextSelection. I guess I can’t say with certainty nothing else is interfering, but I wonder if there’s something I’m overlooking?

I was surprised not to see custom selections discussed very much despite the extensive documentation and discussion around ProseMirror.

The idea is to capture some interactions and explicitly set a custom selection for them. In some cases you’ll also want to use createSelectionBetween.

Undoing back to a custom selection seems to work (try with the gap cursor, for example). As long as your bookmark implementation works this should just automatically do the right thing.

1 Like

Thank you for the clarification, and as always, for your amazing work!