Skip to content

refactor: use selection bookmarks to support all possible selection types #182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

nperez0111
Copy link
Contributor

@nperez0111 nperez0111 commented Apr 15, 2025

This completely overhauls selection restoration to be based on Prosemirror Bookmarks which are used to store & restore selections independent of the current document.
This is useful for y-prosemirror, since it means that we do not have to implement each selection type, yet all of them will work.

These also fallback to a TextSelection.between if a bookmark, if invalid or unimplemented, which is a good default.

Resolves:

Comment on lines +250 to +254
export const relativePositionStore = (pmbinding, pos) => {
const relPos = absolutePositionToRelativePosition(pos, pmbinding.type, pmbinding.mapping)

return (binding = pmbinding) => {
return relativePositionToAbsolutePosition(binding.doc, binding.type, relPos, binding.mapping)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't necessarily have to be exported, I thought it was just a useful abstraction to have. Happy to inline it if we don't want it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant