BitPhinix / slate-yjs

Yjs binding for Slate
https://docs.slate-yjs.dev
MIT License
514 stars 73 forks source link

How to clear cursor state on editor blur #342

Closed rcbevans closed 2 years ago

rcbevans commented 2 years ago

On my page I am using two slate editors for different parts of the same document.

Currently, once a user clicks into the editor, their cursor position is shared with all other collaborators and renders correctly (thanks for the hint to use cursorStateField to differentiate the cursor position data for each), but the cursor position persistes even once the user blurs the editor.

If a user clicks into each editor, other users see a cursor for the user in each of the editors, rather than the editor where their cursor currently is. Is it possible to clear the cursor position data on blur of the slate editor?

rcbevans commented 2 years ago

I added

              onBlur={() => {
                editor.sendCursorPosition(null);
              }}

to the Editable component and this does seem to clear the cursor position when the editor loses focus, however on focus again, the cursor position is not synced again until the user moves the cursor to a new position in the editor text.

BitPhinix commented 2 years ago

Sorry for taking so long to come back to this, will add a option for it in https://github.com/BitPhinix/slate-yjs/pull/363 🙏

BitPhinix commented 2 years ago

It's included via the useUnsetCursorPositionOnBlur hook in https://github.com/BitPhinix/slate-yjs/pull/363/files#diff-5f9695b6035d0b13922dc5a300a83513b0dc0d4a93790b85c9b58d0acb257f0d. Will merge and release a new version of slate-react in 1-2 days