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

Editor selectionUpdate event fires when another user moves their cursor (via CollaborationCursor) #1461

Closed
jamesopti opened this issue Jun 13, 2021 · 1 comment
Labels
Type: Bug The issue or pullrequest is related to a bug

Comments

@jamesopti
Copy link

Description
When using the CollaborationCursor extension, the selectionUpdate event fires when another user is moving their cursor around in the doc.

editor.on('selectionUpdate', () => {
  // This will fire if another user clicks around the doc in their own browser 
})

Steps to reproduce the bug
Steps to reproduce the behavior:

  1. Setup the basic CollaborationCursor demo
  2. Add a listener for editor.on('selectionUpdate', onSelectionUpdate)
  3. Open 2 browsers and click around in 1
  4. Observe both clients firing the event handler

Expected behavior
While it may technically be true that the selection is changing, it would be nice to know if the event is firing due to this client or another.

Suggested API - If there is a notion of this client's id, passing that along would allow filtering. Otherwise, just isThisClient would suffice

editor.on('selectionUpdate', ({ editor, clientId or isThisClient }) => ...)

Additional context
Add any other context about the problem here.

@jamesopti jamesopti added Type: Bug The issue or pullrequest is related to a bug v2 labels Jun 13, 2021
@philippkuehn
Copy link
Contributor

I’ve added the current transaction to the selectionUpdate event so you can check for remote changes now.

import { ySyncPluginKey } from 'y-prosemirror'

new Editor({
  onSelectionUpdate: ({ transaction }) => {
    // ignore changes made by y.js
    if (transaction.getMeta(ySyncPluginKey)) {
      return
    }

    console.log('selection update')
  }
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug The issue or pullrequest is related to a bug
Projects
None yet
Development

No branches or pull requests

2 participants