Skip to content

Commit 76fc703

Browse files
authored
Merge pull request microsoft#144708 from microsoft/rebornix/recovery143538
Fix text output alignment
2 parents 33dd97e + 0bec750 commit 76fc703

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

src/vs/workbench/contrib/notebook/browser/diff/notebookTextDiffEditor.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,20 +379,29 @@ export class NotebookTextDiffEditor extends EditorPane implements INotebookTextD
379379
this._modifiedWebview.dispose();
380380
}
381381

382-
this._modifiedWebview = this.instantiationService.createInstance(BackLayerWebView, this, id, resource, this._notebookOptions.computeDiffWebviewOptions(), undefined) as BackLayerWebView<IDiffCellInfo>;
382+
this._modifiedWebview = this.instantiationService.createInstance(BackLayerWebView, this, id, resource, {
383+
...this._notebookOptions.computeDiffWebviewOptions(),
384+
fontFamily: this._generateFontFamily()
385+
}, undefined) as BackLayerWebView<IDiffCellInfo>;
383386
// attach the webview container to the DOM tree first
384387
this._list.rowsContainer.insertAdjacentElement('afterbegin', this._modifiedWebview.element);
385388
await this._modifiedWebview.createWebview();
386389
this._modifiedWebview.element.style.width = `calc(50% - 16px)`;
387390
this._modifiedWebview.element.style.left = `calc(50%)`;
388391
}
392+
_generateFontFamily(): string {
393+
return this._fontInfo?.fontFamily ?? `"SF Mono", Monaco, Menlo, Consolas, "Ubuntu Mono", "Liberation Mono", "DejaVu Sans Mono", "Courier New", monospace`;
394+
}
389395

390396
private async _createOriginalWebview(id: string, resource: URI): Promise<void> {
391397
if (this._originalWebview) {
392398
this._originalWebview.dispose();
393399
}
394400

395-
this._originalWebview = this.instantiationService.createInstance(BackLayerWebView, this, id, resource, this._notebookOptions.computeDiffWebviewOptions(), undefined) as BackLayerWebView<IDiffCellInfo>;
401+
this._originalWebview = this.instantiationService.createInstance(BackLayerWebView, this, id, resource, {
402+
...this._notebookOptions.computeDiffWebviewOptions(),
403+
fontFamily: this._generateFontFamily()
404+
}, undefined) as BackLayerWebView<IDiffCellInfo>;
396405
// attach the webview container to the DOM tree first
397406
this._list.rowsContainer.insertAdjacentElement('afterbegin', this._originalWebview.element);
398407
await this._originalWebview.createWebview();

src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,10 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD
425425
if (e.compactView || e.focusIndicator || e.insertToolbarPosition || e.cellToolbarLocation || e.dragAndDropEnabled || e.fontSize || e.markupFontSize || e.insertToolbarAlignment) {
426426
this._styleElement?.remove();
427427
this._createLayoutStyles();
428-
this._webview?.updateOptions(this.notebookOptions.computeWebviewOptions());
428+
this._webview?.updateOptions({
429+
...this.notebookOptions.computeWebviewOptions(),
430+
fontFamily: this._generateFontFamily()
431+
});
429432
}
430433

431434
if (this._dimension && this._isVisible) {
@@ -616,6 +619,10 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD
616619
DOM.append(parent, this._overflowContainer);
617620
}
618621

622+
private _generateFontFamily() {
623+
return this._fontInfo?.fontFamily ?? `"SF Mono", Monaco, Menlo, Consolas, "Ubuntu Mono", "Liberation Mono", "DejaVu Sans Mono", "Courier New", monospace`;
624+
}
625+
619626
private _createLayoutStyles(): void {
620627
this._styleElement = DOM.createStyleSheet(this._body);
621628
const {
@@ -647,7 +654,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD
647654
this._generateFontInfo();
648655
}
649656

650-
const fontFamily = this._fontInfo?.fontFamily ?? `"SF Mono", Monaco, Menlo, Consolas, "Ubuntu Mono", "Liberation Mono", "DejaVu Sans Mono", "Courier New", monospace`;
657+
const fontFamily = this._generateFontFamily();
651658

652659
styleSheets.push(`
653660
:root {
@@ -1098,7 +1105,10 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD
10981105
|| oldBottomToolbarDimensions.bottomToolbarHeight !== newBottomToolbarDimensions.bottomToolbarHeight) {
10991106
this._styleElement?.remove();
11001107
this._createLayoutStyles();
1101-
this._webview?.updateOptions(this.notebookOptions.computeWebviewOptions());
1108+
this._webview?.updateOptions({
1109+
...this.notebookOptions.computeWebviewOptions(),
1110+
fontFamily: this._generateFontFamily()
1111+
});
11021112
}
11031113
type WorkbenchNotebookOpenClassification = {
11041114
scheme: { classification: 'SystemMetaData'; purpose: 'FeatureInsight' };
@@ -1348,7 +1358,10 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD
13481358
didDragMarkupCell: that._didDragMarkupCell.bind(that),
13491359
didDropMarkupCell: that._didDropMarkupCell.bind(that),
13501360
didEndDragMarkupCell: that._didEndDragMarkupCell.bind(that)
1351-
}, id, resource, this._notebookOptions.computeWebviewOptions(), this.notebookRendererMessaging.getScoped(this._uuid));
1361+
}, id, resource, {
1362+
...this._notebookOptions.computeWebviewOptions(),
1363+
fontFamily: this._generateFontFamily()
1364+
}, this.notebookRendererMessaging.getScoped(this._uuid));
13521365

13531366
this._webview.element.style.width = '100%';
13541367

src/vs/workbench/contrib/notebook/browser/view/renderers/backLayerWebView.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ interface BacklayerWebviewOptions {
8787
readonly runGutter: number;
8888
readonly dragAndDropEnabled: boolean;
8989
readonly fontSize: number;
90+
readonly fontFamily: string;
9091
readonly markupFontSize: number;
9192
}
9293

@@ -203,6 +204,7 @@ export class BackLayerWebView<T extends ICommonCellInfo> extends Disposable {
203204
'notebook-markdown-min-height': `${this.options.previewNodePadding * 2}px`,
204205
'notebook-markup-font-size': typeof this.options.markupFontSize === 'number' && this.options.markupFontSize > 0 ? `${this.options.markupFontSize}px` : `calc(${this.options.fontSize}px * 1.2)`,
205206
'notebook-cell-output-font-size': `${this.options.fontSize}px`,
207+
'notebook-cell-output-font-family': this.options.fontFamily,
206208
'notebook-cell-markup-empty-content': nls.localize('notebook.emptyMarkdownPlaceholder', "Empty markdown cell, double click or press enter to edit."),
207209
'notebook-cell-renderer-not-found-error': nls.localize({
208210
key: 'notebook.error.rendererNotFound',

0 commit comments

Comments
 (0)