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

Scroll position changes when other clients are editing #31

Closed
tommoor opened this issue Dec 8, 2020 · 7 comments
Closed

Scroll position changes when other clients are editing #31

tommoor opened this issue Dec 8, 2020 · 7 comments

Comments

@tommoor
Copy link
Contributor

tommoor commented Dec 8, 2020

To Reproduce

  • Create a doc long enough to scroll
  • In one client place your cursor at the bottom of the screen and scroll to the top (common behavior when reading)
  • In another client type at the top of the doc
  • The scroll position in the first client will jump to the bottom

Screencast

From the y-prosemirror demo site:

Kapture 2020-12-08 at 15 01 08

I tracked it down to this line – could you enlighten in which circumstances this is supposed to trigger? It feels like it would be fine if remote edits never caused the local scroll state to change.

if (this.beforeTransactionSelection !== null && this._isLocalCursorInView()) {
tr.scrollIntoView()
}

@tommoor tommoor changed the title Doc scrolls about when other users are editing Scroll position changes when other users are editing Dec 8, 2020
@tommoor tommoor changed the title Scroll position changes when other users are editing Scroll position changes when other clients are editing Dec 8, 2020
@dmonad
Copy link
Member

dmonad commented Dec 9, 2020

I can't reproduce this issue in Chrome Version 87.0.4280.66 (Official Build) (64-bit).

The code you mentioned scrolls the window to the current editing position when a remote change happens IF the cursor is currently in view. This prevents weird scrolling behavior when a user is adding/removing a lot of content at the beginning of the document.

@tommoor
Copy link
Contributor Author

tommoor commented Dec 9, 2020

In which case the "if cursor is in view" logic must not be correct 🤔

@dmonad
Copy link
Member

dmonad commented Dec 9, 2020

Apparantly. But your comment doesn't help me to fix the problem. As said, I can't reproduce the issue using the description you gave me.

@tommoor
Copy link
Contributor Author

tommoor commented Dec 9, 2020

I think the key is to scroll up without clicking anywhere outside of the editor in the first window. Probably easiest to reproduce with two machines as this is how it was first found in testing.

Some more debugging, when it reachesisDomSelectionInView the documentElement is actually just the html tag, so seems like it would be safe to guard that this isn't the case? It explains why the calculation fails and causes scroll to jump to the top.

image

@dmonad
Copy link
Member

dmonad commented Dec 10, 2020

That is intended. Maybe the check fails because documentElement.clientHeight is the full height of the website? That is why it is important to specify which browser / which OS you are using...

In your environment, is that different from window.innerHeight? innerHeight might be more appropriate to use here.

@tommoor
Copy link
Contributor Author

tommoor commented Dec 10, 2020

That is why it is important to specify which browser / which OS you are using...

Totally agreed, that information wasn't requested in the template previously though and I thought it would be relatively clear in the gif that it's Chrome on macOS.

@dmonad dmonad closed this as completed in 34a34d3 Dec 15, 2020
@dmonad
Copy link
Member

dmonad commented Dec 15, 2020

This is fixed in y-prosemirror@1.0.5

tommoor pushed a commit to tommoor/remirror that referenced this issue Dec 15, 2020
Includes fixes for scrolling while remote clients are editing and incorrect remote selections
see: yjs/y-prosemirror#31
see: yjs/y-prosemirror#32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants