y-prosemirror icon indicating copy to clipboard operation
y-prosemirror copied to clipboard

Incorrect cursor position after undo

Open philippkuehn opened this issue 4 years ago • 5 comments

Describe the bug As soon as I create multiple nodes one after the other and want to undo this, the cursor stays in the last line. This issue can be reproduced on the official demo page.

To Reproduce Steps to reproduce the behavior:

  1. create paragraph
  2. press enter
  3. press cmd+z/ctrl+z

Expected behavior Cursor should be in the first line instead of the second.

Screenshots https://user-images.githubusercontent.com/2500670/108116413-ce668880-709b-11eb-89ea-dff5a41d6c47.mp4

philippkuehn avatar Feb 16 '21 20:02 philippkuehn

@dmonad ping 👀

philippkuehn avatar Mar 17 '21 17:03 philippkuehn

collab Hey, I have the same bug. Any updates?

bedryck avatar Mar 22 '22 09:03 bedryck

The following is my solution, mainly to change three places:

  1. placing ystate within the undoManager event.
  2. place the memory cursor position within _prosemirrorChanged (too many plug-ins are executed so that oldState does not really represent the last cursor position).
  3. change the stack-item-popped event to stack-item-pop (I added this event myself, so you'll need to modify Yjs as well).

https://github.com/hamflx/y-prosemirror/commit/e44952ef5d8c0adfa3c75062db7622468eea8698

https://github.com/hamflx/yjs/commit/716aa57252f5d0ef5173793b7750207ff6063a48

hamflx avatar Aug 02 '22 08:08 hamflx

Any update on if there will be an official fix?

Jordan-Ellis avatar Oct 05 '22 17:10 Jordan-Ellis

@hamflx thanks for the provided details and patches. After combining them all together with the patch from https://github.com/yjs/y-prosemirror/issues/43#issuecomment-1253668582 I got it working flawlessly. It also restores different types of selections correctly.

By what it looks like all these patches together should resolve the following issues: #43, #101, #139.

@dmonad is it worth starting new PR to address them as it looks like https://github.com/yjs/y-prosemirror/pull/118 is stale?

romansp avatar Oct 18 '23 23:10 romansp