Skip to content

Commit

Permalink
Add notebook markup fontSize setting
Browse files Browse the repository at this point in the history
Fixes #126294
  • Loading branch information
mjbvz committed Nov 9, 2021
1 parent a88cbb5 commit 09dc62b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { NotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookEd
import { isCompositeNotebookEditorInput, NotebookEditorInput, NotebookEditorInputOptions } from 'vs/workbench/contrib/notebook/common/notebookEditorInput';
import { INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService';
import { NotebookService } from 'vs/workbench/contrib/notebook/browser/notebookServiceImpl';
import { CellKind, CellToolbarLocation, CellToolbarVisibility, CellUri, DisplayOrderKey, UndoRedoPerCell, IResolvedNotebookEditorModel, NotebookDocumentBackupData, NotebookTextDiffEditorPreview, NotebookWorkingCopyTypeIdentifier, ShowCellStatusBar, CompactView, FocusIndicator, InsertToolbarLocation, GlobalToolbar, ConsolidatedOutputButton, ShowFoldingControls, DragAndDropEnabled, NotebookCellEditorOptionsCustomizations, ConsolidatedRunButton, TextOutputLineLimit, GlobalToolbarShowLabel, IOutputItemDto } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { CellKind, CellToolbarLocation, CellToolbarVisibility, CellUri, DisplayOrderKey, UndoRedoPerCell, IResolvedNotebookEditorModel, NotebookDocumentBackupData, NotebookTextDiffEditorPreview, NotebookWorkingCopyTypeIdentifier, ShowCellStatusBar, CompactView, FocusIndicator, InsertToolbarLocation, GlobalToolbar, ConsolidatedOutputButton, ShowFoldingControls, DragAndDropEnabled, NotebookCellEditorOptionsCustomizations, ConsolidatedRunButton, TextOutputLineLimit, GlobalToolbarShowLabel, IOutputItemDto, NotebookMarkupFontSize } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IUndoRedoService } from 'vs/platform/undoRedo/common/undoRedo';
import { INotebookEditorModelResolverService } from 'vs/workbench/contrib/notebook/common/notebookEditorModelResolverService';
Expand Down Expand Up @@ -780,6 +780,12 @@ configurationRegistry.registerConfiguration({
default: 30,
tags: ['notebookLayout']
},
[NotebookMarkupFontSize]: {
markdownDescription: nls.localize('notebook.markup.fontSize', "Controls the font size of rendered markup in notebooks. When set to `0`, the value of `#editor.fontSize#` is used."),
type: 'number',
default: 0,
tags: ['notebookLayout']
},
[NotebookCellEditorOptionsCustomizations]: editorOptionsCustomizationSchema
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD
this._updateForNotebookConfiguration();
}

if (e.compactView || e.focusIndicator || e.insertToolbarPosition || e.cellToolbarLocation || e.dragAndDropEnabled || e.fontSize || e.insertToolbarAlignment) {
if (e.compactView || e.focusIndicator || e.insertToolbarPosition || e.cellToolbarLocation || e.dragAndDropEnabled || e.fontSize || e.markupFontSize || e.insertToolbarAlignment) {
this._styleElement?.remove();
this._createLayoutStyles();
this._webview?.updateOptions(this.notebookOptions.computeWebviewOptions());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export class BackLayerWebView<T extends ICommonCellInfo> extends Disposable {
runGutter: number,
dragAndDropEnabled: boolean,
fontSize: number
markupFontSize: number
},
private readonly rendererMessaging: IScopedRendererMessaging | undefined,
@IWebviewService readonly webviewService: IWebviewService,
Expand Down Expand Up @@ -187,6 +188,7 @@ export class BackLayerWebView<T extends ICommonCellInfo> extends Disposable {
runGutter: number,
dragAndDropEnabled: boolean,
fontSize: number
markupFontSize: number
}) {
this.options = options;
this._updateStyles();
Expand Down Expand Up @@ -219,6 +221,7 @@ export class BackLayerWebView<T extends ICommonCellInfo> extends Disposable {
'notebook-markdown-left-margin': `${this.options.markdownLeftMargin}px`,
'notebook-output-node-left-padding': `${this.options.outputNodeLeftPadding}px`,
'notebook-markdown-min-height': `${this.options.previewNodePadding * 2}px`,
'notebook-markup-font-size': `${this.options.markupFontSize}px`,
'notebook-cell-output-font-size': `${this.options.fontSize}px`,
'notebook-cell-markup-empty-content': nls.localize('notebook.emptyMarkdownPlaceholder', "Empty markdown cell, double click or press enter to edit."),
'notebook-cell-renderer-not-found-error': nls.localize({
Expand Down Expand Up @@ -288,6 +291,8 @@ export class BackLayerWebView<T extends ICommonCellInfo> extends Disposable {
white-space: nowrap;
overflow: hidden;
white-space: initial;
font-size: var(--notebook-markup-font-size);
color: var(--theme-ui-foreground);
}
Expand Down
1 change: 1 addition & 0 deletions src/vs/workbench/contrib/notebook/common/notebookCommon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,7 @@ export const ConsolidatedRunButton = 'notebook.consolidatedRunButton';
export const OpenGettingStarted = 'notebook.experimental.openGettingStarted';
export const TextOutputLineLimit = 'notebook.output.textLineLimit';
export const GlobalToolbarShowLabel = 'notebook.globalToolbarShowLabel';
export const NotebookMarkupFontSize = 'notebook.markup.fontSize';

export const enum CellStatusbarAlignment {
Left = 1,
Expand Down
16 changes: 14 additions & 2 deletions src/vs/workbench/contrib/notebook/common/notebookOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { Emitter } from 'vs/base/common/event';
import { Disposable } from 'vs/base/common/lifecycle';
import { IConfigurationChangeEvent, IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { CellToolbarLocation, CellToolbarVisibility, CompactView, ConsolidatedOutputButton, ConsolidatedRunButton, DragAndDropEnabled, ExperimentalInsertToolbarAlignment, FocusIndicator, GlobalToolbar, InsertToolbarLocation, NotebookCellEditorOptionsCustomizations, NotebookCellInternalMetadata, ShowCellStatusBar, ShowCellStatusBarType, ShowFoldingControls } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { CellToolbarLocation, CellToolbarVisibility, CompactView, ConsolidatedOutputButton, ConsolidatedRunButton, DragAndDropEnabled, ExperimentalInsertToolbarAlignment, FocusIndicator, GlobalToolbar, InsertToolbarLocation, NotebookCellEditorOptionsCustomizations, NotebookCellInternalMetadata, NotebookMarkupFontSize, ShowCellStatusBar, ShowCellStatusBarType, ShowFoldingControls } from 'vs/workbench/contrib/notebook/common/notebookCommon';

const SCROLLABLE_ELEMENT_PADDING_TOP = 18;

Expand Down Expand Up @@ -59,6 +59,7 @@ export interface NotebookLayoutConfiguration {
showFoldingControls: 'always' | 'mouseover';
dragAndDropEnabled: boolean;
fontSize: number;
markupFontSize: number;
focusIndicatorLeftMargin: number;
editorOptionsCustomizations: any | undefined;
}
Expand All @@ -78,6 +79,7 @@ export interface NotebookOptionsChangeEvent {
readonly consolidatedRunButton?: boolean;
readonly dragAndDropEnabled?: boolean;
readonly fontSize?: boolean;
readonly markupFontSize?: boolean;
readonly editorOptionsCustomizations?: boolean;
readonly cellBreakpointMargin?: boolean;
}
Expand Down Expand Up @@ -123,6 +125,7 @@ export class NotebookOptions extends Disposable {
const showFoldingControls = this._computeShowFoldingControlsOption();
// const { bottomToolbarGap, bottomToolbarHeight } = this._computeBottomToolbarDimensions(compactView, insertToolbarPosition, insertToolbarAlignment);
const fontSize = this.configurationService.getValue<number>('editor.fontSize');
const markupFontSize = this.configurationService.getValue<number>(NotebookMarkupFontSize);
const editorOptionsCustomizations = this.configurationService.getValue(NotebookCellEditorOptionsCustomizations);

this._layoutConfiguration = {
Expand Down Expand Up @@ -153,6 +156,7 @@ export class NotebookOptions extends Disposable {
insertToolbarAlignment,
showFoldingControls,
fontSize,
markupFontSize: markupFontSize > 0 ? markupFontSize : fontSize,
editorOptionsCustomizations,
};

Expand Down Expand Up @@ -182,6 +186,7 @@ export class NotebookOptions extends Disposable {
const showFoldingControls = e.affectsConfiguration(ShowFoldingControls);
const dragAndDropEnabled = e.affectsConfiguration(DragAndDropEnabled);
const fontSize = e.affectsConfiguration('editor.fontSize');
const markupFontSize = e.affectsConfiguration(NotebookMarkupFontSize);
const editorOptionsCustomizations = e.affectsConfiguration(NotebookCellEditorOptionsCustomizations);

if (
Expand All @@ -198,6 +203,7 @@ export class NotebookOptions extends Disposable {
&& !showFoldingControls
&& !dragAndDropEnabled
&& !fontSize
&& !markupFontSize
&& !editorOptionsCustomizations) {
return;
}
Expand Down Expand Up @@ -260,6 +266,10 @@ export class NotebookOptions extends Disposable {
configuration.fontSize = this.configurationService.getValue<number>('editor.fontSize');
}

if (markupFontSize) {
configuration.markupFontSize = this.configurationService.getValue<number>(NotebookMarkupFontSize) || configuration.fontSize;
}

if (editorOptionsCustomizations) {
configuration.editorOptionsCustomizations = this.configurationService.getValue(NotebookCellEditorOptionsCustomizations);
}
Expand All @@ -281,6 +291,7 @@ export class NotebookOptions extends Disposable {
consolidatedRunButton,
dragAndDropEnabled,
fontSize,
markupFontSize,
editorOptionsCustomizations
});
}
Expand Down Expand Up @@ -456,7 +467,8 @@ export class NotebookOptions extends Disposable {
rightMargin: this._layoutConfiguration.cellRightMargin,
runGutter: this._layoutConfiguration.cellRunGutter,
dragAndDropEnabled: this._layoutConfiguration.dragAndDropEnabled,
fontSize: this._layoutConfiguration.fontSize
fontSize: this._layoutConfiguration.fontSize,
markupFontSize: this._layoutConfiguration.markupFontSize,
};
}

Expand Down

0 comments on commit 09dc62b

Please sign in to comment.