yjs / y-prosemirror

ProseMirror editor binding for Yjs
https://demos.yjs.dev/prosemirror/prosemirror.html
MIT License
328 stars 115 forks source link

Restore NodeSelections correctly #125

Closed sanketdc closed 2 years ago

sanketdc commented 2 years ago

When restoring a selection, currently NodeSelections are erroneously converted to a TextSelection.

Here is the default prosemirror collab example which does not use y-prosemirror the NodeSelection is preserved correctly while syncing updates from another editor:

https://user-images.githubusercontent.com/7319708/181288342-6bd356e6-65ce-439e-ba16-ea1c4dc07bcc.mov

Here is a tiptap example which uses yjs, NodeSelection (use CTRL+CLICK to select a text node) gets converted to a TextSelection while syncing updates from another editor:

https://user-images.githubusercontent.com/7319708/181289479-5f86ad5d-4ee5-4bf6-9051-0521db6a13b1.mov

This commit ensures that NodeSelection is correctly restored as a NodeSelection while syncing yjs updates across editors.

sanketdc commented 2 years ago

Another example demonstrating the issue where a NodeSelection gets converted to a TextSelection using the yjs prosemirror demo at https://github.com/yjs/yjs-demos/tree/main/prosemirror

https://user-images.githubusercontent.com/7319708/181356184-d2fc43e1-4a3f-4fd5-b6f0-44a58958428d.mov

sanketdc commented 2 years ago

yjs prosemirror demo with the changes in this MR retains the NodeSelection as expected:

https://user-images.githubusercontent.com/7319708/181357428-64a792cc-5c3b-4d08-8628-b4fbbb63b4fc.mov