Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:y-prosemirror/src/plugins/cursor-plugin.js
Lines 239 to 242 in fd08cf3
However, in the
createDecorations
function, the valueaw.cursor
is still used. This is reading a hardcoded field with the name"cursor"
from the awareness state.y-prosemirror/src/plugins/cursor-plugin.js
Lines 101 to 112 in fd08cf3
This 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.