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

Cursor is placed in a strange position after changing a node type and undoing it. #101

Open
vitmf opened this issue Mar 30, 2022 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@vitmf
Copy link

vitmf commented Mar 30, 2022

Describe the bug
Cursor is placed in a strange position after changing a node type and undoing it.

To Reproduce
Steps to reproduce the behavior:

  1. type some text in the first line.
  2. type some text in the second line.
  3. change the second line type to heading.
  4. press ctrl+z.
  5. the cursor is placed at the beginning of the second line.
  6. press backspace.
  7. the border of the first line turns to blue.
  8. press backspace again.
  9. the first line is deleted.

Expected behavior
After ctrl+z, the cursor should stay at the end of the second line. Even if the cursor is placed at the beginning of the line, backspace should not create the blue border.

Screenshots
https://user-images.githubusercontent.com/640041/160831412-2a79ee9d-0ad1-4790-844f-3357ac42e4d0.mp4

Environment Information
Chrome 98.0.4758.102 on the demo page.

Additional context
Testing in a local project, it seems the cursor is placed between nodes.

@vitmf vitmf added the bug Something isn't working label Mar 30, 2022
@vitmf
Copy link
Author

vitmf commented May 1, 2022

I don't understand yjs very well, but I think I have some clues.

  1. Shouldn't this ystate initialization be inside the event callbacks?
    view: view => {
    const ystate = ySyncPluginKey.getState(view.state)
    const undoManager = yUndoPluginKey.getState(view.state).undoManager
    undoManager.on('stack-item-added', ({ stackItem }) => {
    const binding = ystate.binding
    if (binding) {
    stackItem.meta.set(binding, yUndoPluginKey.getState(view.state).prevSel)
    }
  2. After an undo, the stack-item-popped event seems to be triggered after the document has been restored, so binding.beforeTransactionSelection is only updated after the selection has already been restored.
  3. As I understand the undo plugin, after a transaction prevSel is saved in the plugin state so it can be added to the meta of the undo stack item. However, if UnderManager merges the edits, won't prevSel refer to a wrong position? (edit: reading more about yjs, this does not seem to be a problem, but more generally, could prevSel refer to the wrong position?)

romansp added a commit to Axure-Software/y-prosemirror that referenced this issue Oct 18, 2023
- introduce RecoverableSelection that wraps current selection and allows it to be restored later
- get ySyncPlugin state inside undoManager event hooks

fixes yjs#43, yjs#101, yjs#139
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants