diff --git a/src/vs/workbench/contrib/terminal/browser/terminalConfigHelper.ts b/src/vs/workbench/contrib/terminal/browser/terminalConfigHelper.ts index 9c9014f7c26def1e5a0db44078983b5a8b7625f3..c149a4694791cf6d91c82cb23df44f2d70a45ae3 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalConfigHelper.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalConfigHelper.ts @@ -124,9 +124,23 @@ export class TerminalConfigHelper implements IBrowserTerminalConfigHelper { fontSize, letterSpacing, lineHeight, - charWidth: rect && rect.width ? rect.width : 0, - charHeight: rect && rect.height ? Math.ceil(rect.height) : 0 + charWidth: 0, + charHeight: 0 }; + + if (rect && rect.width && rect.height) { + this._lastFontMeasurement.charHeight = Math.ceil(rect.height); + // Char width is calculated differently for DOM and the other renderer types. Refer to + // how each renderer updates their dimensions in xterm.js + if (this.config.rendererType === 'dom') { + this._lastFontMeasurement.charWidth = rect.width; + } else { + const scaledCharWidth = rect.width * window.devicePixelRatio; + const scaledCellWidth = scaledCharWidth + Math.round(letterSpacing); + this._lastFontMeasurement.charWidth = Math.round(scaledCellWidth / window.devicePixelRatio); + } + } + return this._lastFontMeasurement; } @@ -167,14 +181,14 @@ export class TerminalConfigHelper implements IBrowserTerminalConfigHelper { // Get the character dimensions from xterm if it's available if (xtermCore) { - if (xtermCore._charSizeService && xtermCore._charSizeService.width && xtermCore._charSizeService.height) { + if (xtermCore._renderService && xtermCore._renderService.dimensions?.actualCellWidth && xtermCore._renderService.dimensions?.actualCellHeight) { return { fontFamily, fontSize, letterSpacing, lineHeight, - charHeight: xtermCore._charSizeService.height, - charWidth: xtermCore._charSizeService.width + charHeight: xtermCore._renderService.dimensions.actualCellHeight, + charWidth: xtermCore._renderService.dimensions.actualCellWidth }; } } diff --git a/src/vs/workbench/contrib/terminal/browser/xterm-private.d.ts b/src/vs/workbench/contrib/terminal/browser/xterm-private.d.ts index 9c57c636a9e4d21261f744ab60f09054d89bb77d..c559ff7b8db6b85c3af1ce738e908c114fa120a2 100644 --- a/src/vs/workbench/contrib/terminal/browser/xterm-private.d.ts +++ b/src/vs/workbench/contrib/terminal/browser/xterm-private.d.ts @@ -17,6 +17,10 @@ export interface XTermCore { }; _renderService: { + dimensions: { + actualCellWidth: number; + actualCellHeight: number; + }, _renderer: { _renderLayers: any[]; };