Skip to content
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

Fix cursorStateField bug #159

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

Fix cursorStateField bug #159

wants to merge 7 commits into from

Conversation

andrictham
Copy link

@andrictham andrictham commented Jul 11, 2024

Summary

This PR fixes an issue with the cursorStateField param that’s passed into yCursorPlugin.

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:

awareness.setLocalStateField(cursorStateField, {
anchor,
head
})

However, in the createDecorations function, the value aw.cursor is still used. This is reading a hardcoded field with the name "cursor" from the awareness state.

let anchor = relativePositionToAbsolutePosition(
y,
ystate.type,
Y.createRelativePositionFromJSON(aw.cursor.anchor),
ystate.binding.mapping
)
let head = relativePositionToAbsolutePosition(
y,
ystate.type,
Y.createRelativePositionFromJSON(aw.cursor.head),
ystate.binding.mapping
)

This results in cursors not rendering properly if you set cursorStateField to a custom value.

Proposed Changes

  • All references to a hardcoded "cursor" field are replaced with a dynamic reference to the field name set in cursorStateField.

Tests

@andrictham
Copy link
Author

@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 😀

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.

Update current.cursor references to current[cursorStateField]?
1 participant