Fix editor scroll jumping randomly after window refocus (#28795)#317477
Open
jing11223344 wants to merge 1 commit into
Open
Fix editor scroll jumping randomly after window refocus (#28795)#317477jing11223344 wants to merge 1 commit into
jing11223344 wants to merge 1 commit into
Conversation
Detect and discard stale wheel events that Chromium accumulates while the VS Code window is unfocused. When the window regains focus, Chromium replays these accumulated events all at once, causing the editor to jump to seemingly random positions. The fix tracks the last wheel event timestamp and the last window focus time. If a wheel event arrives after a significant gap (>400ms) and the window was refocused in that gap, it is a replayed stale event and is discarded. Fixes microsoft#28795
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Mitigates random editor scroll jumps after refocusing the window by filtering out wheel events that Chromium/Electron may replay after focus is regained.
Changes:
- Track last processed wheel-event time and last window-focus time on
AbstractScrollableElement. - Add a window
focuslistener to record refocus time. - Discard wheel events deemed “stale replay” based on a >400ms gap combined with a refocus during that gap.
Comment on lines
+455
to
+463
| const timeSinceLastWheel = now - this._lastWheelEventTime; | ||
| const refocusedSinceLastWheel = this._windowFocusTime > this._lastWheelEventTime; | ||
| this._lastWheelEventTime = now; | ||
| if (refocusedSinceLastWheel && timeSinceLastWheel > 400) { | ||
| // The window was just refocused after a gap of >400ms without | ||
| // any wheel activity. These events were queued while unfocused | ||
| // and should be discarded to prevent scroll jumps. | ||
| return; | ||
| } |
| // accumulates while the window is unfocused and replays on focus. | ||
| // See https://github.com/microsoft/vscode/issues/28795 | ||
| this._register(dom.addDisposableListener(this._domNode.ownerDocument?.defaultView ?? window, 'focus', () => { | ||
| this._windowFocusTime = Date.now(); |
| const timeSinceLastWheel = now - this._lastWheelEventTime; | ||
| const refocusedSinceLastWheel = this._windowFocusTime > this._lastWheelEventTime; | ||
| this._lastWheelEventTime = now; | ||
| if (refocusedSinceLastWheel && timeSinceLastWheel > 400) { |
Contributor
|
@jing11223344 please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR fixes issue #28795 where the VS Code editor scrolls to random positions after switching back from another window (browser, terminal, etc.).
Root Cause
Chromium/Electron accumulates wheel scroll events while the VS Code window is not focused. When the window regains focus, these stale accumulated events are replayed all at once, causing the editor to jump.
Fix
In , track the last wheel event timestamp and the last window focus time. When a wheel event arrives after a gap of >400ms and the window was refocused during that gap, the event is identified as a replayed stale event and discarded.
Testing
Fixes #28795