Skip to content

Commit 5b0460a

Browse files
committed
Change terminal dimensions based on renderer type
The canvas and webgl renderers use a flat integer for width whereas dom uses a floating point number. This was causing canvas/webgl to be more narrow than they should be. Since changing rendererType is a pretty infrequent thing it should be fine to resize for this. Fixes microsoft#86425
1 parent ddebb29 commit 5b0460a

2 files changed

Lines changed: 23 additions & 5 deletions

File tree

src/vs/workbench/contrib/terminal/browser/terminalConfigHelper.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,23 @@ export class TerminalConfigHelper implements IBrowserTerminalConfigHelper {
124124
fontSize,
125125
letterSpacing,
126126
lineHeight,
127-
charWidth: rect && rect.width ? rect.width : 0,
128-
charHeight: rect && rect.height ? Math.ceil(rect.height) : 0
127+
charWidth: 0,
128+
charHeight: 0
129129
};
130+
131+
if (rect && rect.width && rect.height) {
132+
this._lastFontMeasurement.charHeight = Math.ceil(rect.height);
133+
// Char width is calculated differently for DOM and the other renderer types. Refer to
134+
// how each renderer updates their dimensions in xterm.js
135+
if (this.config.rendererType === 'dom') {
136+
this._lastFontMeasurement.charWidth = rect.width;
137+
} else {
138+
const scaledCharWidth = rect.width * window.devicePixelRatio;
139+
const scaledCellWidth = scaledCharWidth + Math.round(letterSpacing);
140+
this._lastFontMeasurement.charWidth = Math.round(scaledCellWidth / window.devicePixelRatio);
141+
}
142+
}
143+
130144
return this._lastFontMeasurement;
131145
}
132146

@@ -167,14 +181,14 @@ export class TerminalConfigHelper implements IBrowserTerminalConfigHelper {
167181

168182
// Get the character dimensions from xterm if it's available
169183
if (xtermCore) {
170-
if (xtermCore._charSizeService && xtermCore._charSizeService.width && xtermCore._charSizeService.height) {
184+
if (xtermCore._renderService && xtermCore._renderService.dimensions?.actualCellWidth && xtermCore._renderService.dimensions?.actualCellHeight) {
171185
return {
172186
fontFamily,
173187
fontSize,
174188
letterSpacing,
175189
lineHeight,
176-
charHeight: xtermCore._charSizeService.height,
177-
charWidth: xtermCore._charSizeService.width
190+
charHeight: xtermCore._renderService.dimensions.actualCellHeight,
191+
charWidth: xtermCore._renderService.dimensions.actualCellWidth
178192
};
179193
}
180194
}

src/vs/workbench/contrib/terminal/browser/xterm-private.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ export interface XTermCore {
1717
};
1818

1919
_renderService: {
20+
dimensions: {
21+
actualCellWidth: number;
22+
actualCellHeight: number;
23+
},
2024
_renderer: {
2125
_renderLayers: any[];
2226
};

0 commit comments

Comments
 (0)