fix: terminal canvas misalignment on zoom level change#309165
Open
ammaarrahmed wants to merge 1 commit intomicrosoft:mainfrom
Open
fix: terminal canvas misalignment on zoom level change#309165ammaarrahmed wants to merge 1 commit intomicrosoft:mainfrom
ammaarrahmed wants to merge 1 commit intomicrosoft:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes integrated terminal canvas/text misalignment after zoom changes by triggering a terminal relayout when zoom/DPR changes, ensuring font measurements and xterm rendering are recalculated promptly.
Changes:
- Subscribe to
PixelRatio.onDidChangeto react todevicePixelRatiochanges and trigger a relayout. - Subscribe to
onDidChangeZoomLevelto react to Electron zoom level changes and trigger the same relayout path. - Force an xterm redraw and mark layout settings as stale before recalculating layout/resize.
Author
|
@microsoft-github-policy-service agree |
When the user changes the editor zoom level (Ctrl++/Ctrl+-), the integrated terminal canvas failed to repaint and align correctly. The prompt text would get clipped, disappear, or render with excess blank space. Inline suggestion ghost text also misaligned. Root cause: the terminal's dimension calculations use window.devicePixelRatio for canvas rendering and font measurements, but no listener existed to trigger a layout recalculation when the pixel ratio changed due to zoom. This adds two event listeners in the TerminalInstance constructor: - PixelRatio.onDidChange: fires when devicePixelRatio changes - onDidChangeZoomLevel: fires from Electron's zoom API Both trigger a deferred (50ms) full layout recalculation that: 1. Marks font metrics as stale (_layoutSettingsChanged = true) 2. Clears the WebGL/canvas texture atlas (forceRedraw) 3. Runs the full layout() path to recalculate cols/rows This matches the established pattern used by the editor, color picker, debug toolbar, breadcrumbs, and notebook components, all of which already subscribe to PixelRatio.onDidChange. Fixes microsoft#309160 Signed-off-by: Ammaar Ahmed <ammaarlatif53@gmail.com>
4df010f to
d8d5dd8
Compare
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.
Summary
When the user changes the editor zoom level (Ctrl++/Ctrl+-), the integrated terminal canvas fails to repaint and align correctly. The prompt text gets clipped, disappears, or renders with excess blank space. Inline suggestion ghost text also misaligns.
Root Cause
The terminal's dimension calculations (
getXtermScaledDimensions,_measureFont) usewindow.devicePixelRatiofor canvas rendering and font measurements, but no listener existed to trigger a layout recalculation when the pixel ratio changed due to zoom. Switching tabs worked around the issue becausesetVisible(true)calls_resize(), which recalculates dimensions with the now-current DPR.Fix
Two event listeners are added in the
TerminalInstanceconstructor:PixelRatio.onDidChange— fires whendevicePixelRatiochanges (e.g. browser zoom, display scale)onDidChangeZoomLevel— fires from Electron's zoom API (e.g.Ctrl++/Ctrl+-)Both trigger a shared handler that defers (50 ms for DOM settling) a full layout recalculation:
_layoutSettingsChanged = true)forceRedraw())layout()path to recalculate cols/rowsPrecedent
This matches the established pattern used by other VS Code components that already subscribe to
PixelRatio.onDidChange:editorDom.ts)Demo
Screencast.from.2026-04-11.10-28-43.webm
Testing Checklist
Ctrl++/Ctrl+-— terminal repaints correctly, no clipping or blank spacetsgo)valid-layers-check)How to Test
Ctrl++orCtrl+-to zoom in/outFixes #309160