This repository was archived by the owner on Apr 16, 2026. It is now read-only.
Don't try to scroll if editor isn't visible#1350
Closed
njx wants to merge 1 commit intocodemirror:masterfrom
adobe:avoid-invisible-scroll
Closed
Don't try to scroll if editor isn't visible#1350njx wants to merge 1 commit intocodemirror:masterfrom adobe:avoid-invisible-scroll
njx wants to merge 1 commit intocodemirror:masterfrom
adobe:avoid-invisible-scroll
Conversation
Member
|
Fair enough. I've merged this as is. There may be other similar corner cases that lead to weird scrolling resets, but I haven't run into them yet. |
Author
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
If someone calls
scrollTo(), and then hides the editor before the scroll event is processed, CodeMirror will try to process the scroll while it's hidden, which seems to end up scrolling to (0,0). (I didn't dig into why that happens, but it's plausible to me that the scrolling management stuff would get confused if it's called while the editor is invisible.)This patch makes it so CM doesn't try to process scrolls while hidden. Since the scroll position is saved in the doc state, it appears that the scroll position gets correctly reset to the
scrollTo()position when CM becomes visible again anyway (I didn't trace through to fully verify this, but that appears to be the behavior I'm seeing).This is somewhat similar to, but different from, the issue and fix for #1236--there, the issue was that a bogus value was explicitly calculated during
endOperation()while the editor was hidden. Here, the editor is actually still visible in theendOperation()of thescrollTo()--the problem is that it becomes hidden before the resulting scroll event is asynchronously processed.