From e8d4fba3c06614585fcfdb75428f9ea5f5047412 Mon Sep 17 00:00:00 2001 From: Chris LaFreniere <40371649+chlafreniere@users.noreply.github.com> Date: Mon, 1 Jul 2019 16:10:20 -0700 Subject: [PATCH] Support non-default font sizes in notebooks (#6222) * Support non-default font sizes notebooks * pr comments --- .../modelComponents/queryTextEditor.ts | 15 ++++++++------- .../parts/notebook/cellViews/code.component.ts | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/sql/workbench/electron-browser/modelComponents/queryTextEditor.ts b/src/sql/workbench/electron-browser/modelComponents/queryTextEditor.ts index d9c0c5187e..18747c178b 100644 --- a/src/sql/workbench/electron-browser/modelComponents/queryTextEditor.ts +++ b/src/sql/workbench/electron-browser/modelComponents/queryTextEditor.ts @@ -35,13 +35,13 @@ export class QueryTextEditor extends BaseTextEditor { public static ID = 'modelview.editors.textEditor'; private _dimension: DOM.Dimension; - private _config: editorCommon.IConfiguration; private _minHeight: number = 0; private _maxHeight: number = 4000; private _selected: boolean; private _hideLineNumbers: boolean; private _editorWorkspaceConfig; private _scrollbarHeight: number; + private _lineHeight: number; constructor( @ITelemetryService telemetryService: ITelemetryService, @@ -132,9 +132,9 @@ export class QueryTextEditor extends BaseTextEditor { public setHeightToScrollHeight(configChanged?: boolean): void { let editorWidget = this.getControl() as ICodeEditor; - this._config = new Configuration(true, undefined, editorWidget.getDomNode(), this.accessibilityService); + let layoutInfo = editorWidget.getLayoutInfo(); if (!this._scrollbarHeight) { - this._scrollbarHeight = this._config.editor.viewInfo.scrollbar.horizontalScrollbarSize; + this._scrollbarHeight = layoutInfo.horizontalScrollbarHeight; } let editorWidgetModel = editorWidget.getModel(); if (!editorWidgetModel) { @@ -151,26 +151,27 @@ export class QueryTextEditor extends BaseTextEditor { let shouldAddHorizontalScrollbarHeight = false; if (!this._editorWorkspaceConfig || configChanged) { this._editorWorkspaceConfig = this.workspaceConfigurationService.getValue('editor'); + this._lineHeight = editorWidget.getConfiguration().lineHeight; } let wordWrapEnabled: boolean = this._editorWorkspaceConfig && this._editorWorkspaceConfig['wordWrap'] && this._editorWorkspaceConfig['wordWrap'] === 'on' ? true : false; if (wordWrapEnabled) { for (let line = 1; line <= lineCount; line++) { // 4 columns is equivalent to the viewport column width and the edge of the editor - if (editorWidgetModel.getLineMaxColumn(line) >= this._config.editor.layoutInfo.viewportColumn + 4) { + if (editorWidgetModel.getLineMaxColumn(line) >= layoutInfo.viewportColumn + 4) { // Subtract 1 because the first line should not count as a wrapped line - numberWrappedLines += Math.ceil(editorWidgetModel.getLineMaxColumn(line) / this._config.editor.layoutInfo.viewportColumn) - 1; + numberWrappedLines += Math.ceil(editorWidgetModel.getLineMaxColumn(line) / layoutInfo.viewportColumn) - 1; } } } else { for (let line = 1; line <= lineCount; line++) { // The horizontal scrollbar always appears 1 column past the viewport column when word wrap is disabled - if (editorWidgetModel.getLineMaxColumn(line) >= this._config.editor.layoutInfo.viewportColumn + 1) { + if (editorWidgetModel.getLineMaxColumn(line) >= layoutInfo.viewportColumn + 1) { shouldAddHorizontalScrollbarHeight = true; break; } } } - let editorHeightUsingLines = this._config.editor.lineHeight * (lineCount + numberWrappedLines); + let editorHeightUsingLines = this._lineHeight * (lineCount + numberWrappedLines); let editorHeightUsingMinHeight = Math.max(Math.min(editorHeightUsingLines, this._maxHeight), this._minHeight); editorHeightUsingMinHeight = shouldAddHorizontalScrollbarHeight ? editorHeightUsingMinHeight + this._scrollbarHeight : editorHeightUsingMinHeight; this.setHeight(editorHeightUsingMinHeight); diff --git a/src/sql/workbench/parts/notebook/cellViews/code.component.ts b/src/sql/workbench/parts/notebook/cellViews/code.component.ts index 7c94c8a816..0e82b0acca 100644 --- a/src/sql/workbench/parts/notebook/cellViews/code.component.ts +++ b/src/sql/workbench/parts/notebook/cellViews/code.component.ts @@ -226,7 +226,7 @@ export class CodeComponent extends AngularDisposable implements OnInit, OnChange setTimeout(() => this._layoutEmitter.fire(), 250); })); this._register(this._configurationService.onDidChangeConfiguration(e => { - if (e.affectsConfiguration('editor.wordWrap')) { + if (e.affectsConfiguration('editor.wordWrap') || e.affectsConfiguration('editor.fontSize')) { this._editor.setHeightToScrollHeight(true); } }));