Prosemirror-view: scrollToSelection and resetScrollPos

Hi,

I’m working with prosemirror in a project where we need more control over scrolling after transactions take place. The issue for what I’m doing is that if I want to take more control over the view.dom scrolling I need to do all of that outside of the view: update. This requires references various amounts of tracking outside of the prosemirror api.

The closest you can get to updateState is by overriding the dispatchTransaction prop on the EditorView. So what would help for me is if there was a way to trigger off the if (scrollToSelection) and else if (oldScrollPos). The most useful place for our customized scrolling is to use a tr.setMeta and save it in the plugin for view.update. Unfortunately, if the selection changes it likes to move the screen around.

We are trying to emulate some functionality as part of our project that is not natively supported and the selection position is important but, the way that scrolling is handled with prosemirror-view is not easy to override.

Also, It would be nice to be able to decide if we want the view to update where the caret is as well, or override/disable that functionality entirely and substitute our own. I’m not sure if I’m missing something here either.

I’m not sure you’d want to turn off the second – a redraw may potentially collapse the content and then recreate it, moving your scroll position back to zero from anywhere. Even for custom scroll behavior, you’d want the old scroll position as a baseline, I expect.

Would just having a way to override/disable scrolling the selection into view after a transaction work?

Yes. Just the ability to tell the view to not scroll or override for a particular updateState is more than sufficient.

For now I will rig up something simple and workable in the dispatchTransaction prop for the editorview. I hope you might consider my suggestion, even if it is low priority.

Does this patch help for you?

Also yes, We’re using it now, Thank you very much for that. Simply calling scrollIntoView now is sufficient to trigger that prop it seems.