提交 d569aba4 编写于 作者: D Daniel Imms

Use xterm's to calc terminal char dimensions if available

Fixes #44608
上级 d2d760ce
...@@ -606,5 +606,6 @@ declare module 'vscode-xterm' { ...@@ -606,5 +606,6 @@ declare module 'vscode-xterm' {
webLinksInit(handler?: (event: MouseEvent, uri: string) => void, options?: ILinkMatcherOptions): void; webLinksInit(handler?: (event: MouseEvent, uri: string) => void, options?: ILinkMatcherOptions): void;
winptyCompatInit(): void; winptyCompatInit(): void;
charMeasure?: { height: number, width: number }
} }
} }
\ No newline at end of file
...@@ -14,6 +14,7 @@ import { ITerminalConfiguration, ITerminalConfigHelper, ITerminalFont, IShellLau ...@@ -14,6 +14,7 @@ import { ITerminalConfiguration, ITerminalConfigHelper, ITerminalFont, IShellLau
import Severity from 'vs/base/common/severity'; import Severity from 'vs/base/common/severity';
import { isFedora } from 'vs/workbench/parts/terminal/electron-browser/terminal'; import { isFedora } from 'vs/workbench/parts/terminal/electron-browser/terminal';
import { IChoiceService } from 'vs/platform/dialogs/common/dialogs'; import { IChoiceService } from 'vs/platform/dialogs/common/dialogs';
import { Terminal as XTermTerminal } from 'vscode-xterm';
const DEFAULT_LINE_HEIGHT = 1.0; const DEFAULT_LINE_HEIGHT = 1.0;
...@@ -50,20 +51,12 @@ export class TerminalConfigHelper implements ITerminalConfigHelper { ...@@ -50,20 +51,12 @@ export class TerminalConfigHelper implements ITerminalConfigHelper {
} }
private _measureFont(fontFamily: string, fontSize: number, lineHeight: number): ITerminalFont { private _measureFont(fontFamily: string, fontSize: number, lineHeight: number): ITerminalFont {
// Return cached font if no config changed
if (this._lastFontMeasurement &&
this._lastFontMeasurement.fontFamily === fontFamily &&
this._lastFontMeasurement.fontSize === fontSize &&
this._lastFontMeasurement.lineHeight === lineHeight) {
return this._lastFontMeasurement;
}
// Create charMeasureElement if it hasn't been created or if it was orphaned by its parent // Create charMeasureElement if it hasn't been created or if it was orphaned by its parent
if (!this._charMeasureElement || !this._charMeasureElement.parentElement) { if (!this._charMeasureElement || !this._charMeasureElement.parentElement) {
this._charMeasureElement = document.createElement('div'); this._charMeasureElement = document.createElement('div');
this.panelContainer.appendChild(this._charMeasureElement); this.panelContainer.appendChild(this._charMeasureElement);
} }
// TODO: This should leverage CharMeasure
const style = this._charMeasureElement.style; const style = this._charMeasureElement.style;
style.display = 'block'; style.display = 'block';
style.fontFamily = fontFamily; style.fontFamily = fontFamily;
...@@ -92,7 +85,7 @@ export class TerminalConfigHelper implements ITerminalConfigHelper { ...@@ -92,7 +85,7 @@ export class TerminalConfigHelper implements ITerminalConfigHelper {
* Gets the font information based on the terminal.integrated.fontFamily * Gets the font information based on the terminal.integrated.fontFamily
* terminal.integrated.fontSize, terminal.integrated.lineHeight configuration properties * terminal.integrated.fontSize, terminal.integrated.lineHeight configuration properties
*/ */
public getFont(excludeDimensions?: boolean): ITerminalFont { public getFont(xterm?: XTermTerminal, excludeDimensions?: boolean): ITerminalFont {
const editorConfig = this._configurationService.getValue<IEditorOptions>('editor'); const editorConfig = this._configurationService.getValue<IEditorOptions>('editor');
let fontFamily = this.config.fontFamily || editorConfig.fontFamily; let fontFamily = this.config.fontFamily || editorConfig.fontFamily;
...@@ -115,6 +108,20 @@ export class TerminalConfigHelper implements ITerminalConfigHelper { ...@@ -115,6 +108,20 @@ export class TerminalConfigHelper implements ITerminalConfigHelper {
}; };
} }
// Get the character dimensions from xterm if it's available
if (xterm) {
if (xterm.charMeasure && xterm.charMeasure.width && xterm.charMeasure.height) {
return {
fontFamily,
fontSize,
lineHeight,
charHeight: xterm.charMeasure.height,
charWidth: xterm.charMeasure.width
};
}
}
// Fall back to measuring the font ourselves
return this._measureFont(fontFamily, fontSize, lineHeight); return this._measureFont(fontFamily, fontSize, lineHeight);
} }
......
...@@ -223,7 +223,7 @@ export class TerminalInstance implements ITerminalInstance { ...@@ -223,7 +223,7 @@ export class TerminalInstance implements ITerminalInstance {
return null; return null;
} }
const font = this._configHelper.getFont(); const font = this._configHelper.getFont(this._xterm);
// Because xterm.js converts from CSS pixels to actual pixels through // Because xterm.js converts from CSS pixels to actual pixels through
// the use of canvas, window.devicePixelRatio needs to be used here in // the use of canvas, window.devicePixelRatio needs to be used here in
...@@ -243,7 +243,7 @@ export class TerminalInstance implements ITerminalInstance { ...@@ -243,7 +243,7 @@ export class TerminalInstance implements ITerminalInstance {
private _getDimension(width: number, height: number): Dimension { private _getDimension(width: number, height: number): Dimension {
// The font needs to have been initialized // The font needs to have been initialized
const font = this._configHelper.getFont(); const font = this._configHelper.getFont(this._xterm);
if (!font || !font.charWidth || !font.charHeight) { if (!font || !font.charWidth || !font.charHeight) {
return null; return null;
} }
...@@ -285,7 +285,7 @@ export class TerminalInstance implements ITerminalInstance { ...@@ -285,7 +285,7 @@ export class TerminalInstance implements ITerminalInstance {
Terminal.strings.tooMuchOutput = nls.localize('terminal.integrated.a11yTooMuchOutput', 'Too much output to announce, navigate to rows manually to read'); Terminal.strings.tooMuchOutput = nls.localize('terminal.integrated.a11yTooMuchOutput', 'Too much output to announce, navigate to rows manually to read');
} }
const accessibilitySupport = this._configurationService.getValue<IEditorOptions>('editor').accessibilitySupport; const accessibilitySupport = this._configurationService.getValue<IEditorOptions>('editor').accessibilitySupport;
const font = this._configHelper.getFont(true); const font = this._configHelper.getFont(undefined, true);
this._xterm = new Terminal({ this._xterm = new Terminal({
scrollback: this._configHelper.config.scrollback, scrollback: this._configHelper.config.scrollback,
theme: this._getXtermTheme(), theme: this._getXtermTheme(),
...@@ -1096,7 +1096,7 @@ export class TerminalInstance implements ITerminalInstance { ...@@ -1096,7 +1096,7 @@ export class TerminalInstance implements ITerminalInstance {
} }
if (this._xterm) { if (this._xterm) {
const font = this._configHelper.getFont(); const font = this._configHelper.getFont(this._xterm);
// Only apply these settings when the terminal is visible so that // Only apply these settings when the terminal is visible so that
// the characters are measured correctly. // the characters are measured correctly.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册