ProseMirror / prosemirror

The ProseMirror WYSIWYM editor
http://prosemirror.net/
MIT License
7.53k stars 334 forks source link

Provide a Command that will undo without scrollIntoView #1451

Closed Divs-B closed 3 months ago

Divs-B commented 3 months ago

We have a use case in prosemirror elements where we would like to do undo the changes without having scrollIntoView behaviour.

We want to provide a PR on this but we are not quite sure how to proceed with this like:

If you can help in having undo without scroll with any of above suggestion that would be great. We will look forward to your response. Thank you

marijnh commented 3 months ago

Even if it doesn't scroll, undo/redo will also move the selection. Are you sure just disabling the scroll behavior is what you want here, or do you also want to leave the selection alone?

jonathonherbert commented 3 months ago

We are happy with the selection, but the scrolling side effect is causing us problems.

That's because in prosemirror-elements, when we're rendering structured data, we often delegate a field to a nested ProseMirror instance, using the method outlined in the footnote example. On undo, we dispatch an undo event on the outer editor in the same way.

The difficulty is that the outer editor cannot reason about the inner editor's contents, and so I suspect is scrolling to the position at which the container NodeView first starts. The difference in scroll behaviour is hard to spot for small NodeViews, but as the rendered element gets larger, it becomes increasingly apparent.

One reproduction would be to write a very large footnote in the footnote demo, and then undo. You can see the outer editor scrolls to the footnote anchor, rather than the inner selection.

We were planning to resolve this by dispatching an undo event that does not call scrollIntoView on the outer editor, and instead manually calling scrollIntoView on the inner editor after the inner editor receives the transaction with the undo state in some way.

marijnh commented 3 months ago

Does attached patch look like it would solve your problem?

jonathonherbert commented 3 months ago

Yes, that looks good. Thanks for your help!

marijnh commented 3 months ago

Tagged this as prosemirror-history 1.4.0