From 569be8eb24a88a91cfe8aa0d0755ae6c2eda5c6f Mon Sep 17 00:00:00 2001 From: Lucy Zhang Date: Fri, 8 Jan 2021 14:45:26 -0800 Subject: [PATCH] Add setting to customize notebook markdown preview line height (#13923) * add md preview line height settings * remove if condition * listen for configuration change * change setting description * only change line height outside of edit mode * set minimum line height to 1 * combine ondidchangeconfiguration callbacks --- .../notebook/browser/cellViews/textCell.component.ts | 9 +++++++-- .../contrib/notebook/browser/notebook.contribution.ts | 6 ++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/sql/workbench/contrib/notebook/browser/cellViews/textCell.component.ts b/src/sql/workbench/contrib/notebook/browser/cellViews/textCell.component.ts index 497dd9ee0b..9815076b9b 100644 --- a/src/sql/workbench/contrib/notebook/browser/cellViews/textCell.component.ts +++ b/src/sql/workbench/contrib/notebook/browser/cellViews/textCell.component.ts @@ -95,6 +95,7 @@ export class TextCellComponent extends CellView implements OnInit, OnChanges { private markdownRenderer: NotebookMarkdownRenderer; private markdownResult: IMarkdownRenderResult; private _htmlMarkdownConverter: HTMLMarkdownConverter; + private markdownPreviewLineHeight: number; public readonly onDidClickLink = this._onDidClickLink.event; public previewFeaturesEnabled: boolean = false; public doubleClickEditEnabled: boolean; @@ -110,6 +111,7 @@ export class TextCellComponent extends CellView implements OnInit, OnChanges { super(); this.markdownRenderer = this._instantiationService.createInstance(NotebookMarkdownRenderer); this.doubleClickEditEnabled = this._configurationService.getValue('notebook.enableDoubleClickEdit'); + this.markdownPreviewLineHeight = this._configurationService.getValue('notebook.markdownPreviewLineHeight'); this._register(toDisposable(() => { if (this.markdownResult) { this.markdownResult.dispose(); @@ -117,9 +119,11 @@ export class TextCellComponent extends CellView implements OnInit, OnChanges { })); this._register(this._configurationService.onDidChangeConfiguration(e => { this.previewFeaturesEnabled = this._configurationService.getValue('workbench.enablePreviewFeatures'); - })); - this._register(this._configurationService.onDidChangeConfiguration(e => { this.doubleClickEditEnabled = this._configurationService.getValue('notebook.enableDoubleClickEdit'); + if (e.affectsConfiguration('notebook.markdownPreviewLineHeight')) { + this.markdownPreviewLineHeight = this._configurationService.getValue('notebook.markdownPreviewLineHeight'); + this.updatePreview(); + } })); } @@ -237,6 +241,7 @@ export class TextCellComponent extends CellView implements OnInit, OnChanges { if (this._previewMode) { let outputElement = this.output.nativeElement; outputElement.innerHTML = this.markdownResult.element.innerHTML; + outputElement.style.lineHeight = this.markdownPreviewLineHeight.toString(); this.cellModel.renderedOutputTextContent = this.getRenderedTextOutput(); outputElement.focus(); } diff --git a/src/sql/workbench/contrib/notebook/browser/notebook.contribution.ts b/src/sql/workbench/contrib/notebook/browser/notebook.contribution.ts index abbf3c19b3..7f8bcc07b3 100644 --- a/src/sql/workbench/contrib/notebook/browser/notebook.contribution.ts +++ b/src/sql/workbench/contrib/notebook/browser/notebook.contribution.ts @@ -231,6 +231,12 @@ configurationRegistry.registerConfiguration({ 'default': false, 'description': localize('notebook.saveConnectionName', "(Preview) Save connection name in notebook metadata.") }, + 'notebook.markdownPreviewLineHeight': { + 'type': 'number', + 'default': 1.5, + 'minimum': 1, + 'description': localize('notebook.markdownPreviewLineHeight', "Controls the line height used in the notebook markdown preview. This number is relative to the font size.") + } } });