Open andrictham opened 1 month ago
@dmonad I wonder if it’s possible to get this merged, or if not, is there something I’m misunderstanding about how cursorStateField
is supposed to work, or something I'm missing in my PR?
I’m reliant on this fix so I can get subdocuments working in my app.
Let me know how I can help 😀
Summary
This PR fixes an issue with the
cursorStateField
param that’s passed intoyCursorPlugin
.Setting
cursorStateField
enables awareness state to be namespaced, so that cursors from different subdocuments syncing over the same provider will be able to read and write their own cursor state.However, it is currently broken. Setting
cursorStateField
doesn’t work as intended: the cursor plugin writes cursor state to the correct field, but doesn’t read back from it when rendering cursors.This fixes #86
Current Behavior
If a custom value of
cursorStateField
is set, the cursor plugin correctly uses it to set awareness state: https://github.com/yjs/y-prosemirror/blob/fd08cf3c7c307c1446178765baa94603a3a8416a/src/plugins/cursor-plugin.js#L239-L242However, in the
createDecorations
function, the valueaw.cursor
is still used. This is reading a hardcoded field with the name"cursor"
from the awareness state. https://github.com/yjs/y-prosemirror/blob/fd08cf3c7c307c1446178765baa94603a3a8416a/src/plugins/cursor-plugin.js#L101-L112This results in cursors not rendering properly if you set
cursorStateField
to a custom value.Proposed Changes
"cursor"
field are replaced with a dynamic reference to the field name set incursorStateField
.Tests
npm run test
and confirmed that all tests are successfulcursorStateField
param, each subdocument’s cursor state will now sync to separate awareness fields.