From 0128b0ce3db6b56c55bda48256edfea2ebf930e0 Mon Sep 17 00:00:00 2001 From: Peng Lyu Date: Fri, 9 Jun 2023 12:28:36 -0700 Subject: [PATCH] Fix #178829. Update editor options for iw input (#184749) --- .../interactive/browser/interactiveEditor.ts | 56 ++++++++++++++----- 1 file changed, 41 insertions(+), 15 deletions(-) diff --git a/src/vs/workbench/contrib/interactive/browser/interactiveEditor.ts b/src/vs/workbench/contrib/interactive/browser/interactiveEditor.ts index 56999d92b7b..faf374d8746 100644 --- a/src/vs/workbench/contrib/interactive/browser/interactiveEditor.ts +++ b/src/vs/workbench/contrib/interactive/browser/interactiveEditor.ts @@ -61,6 +61,8 @@ import { isEqual } from 'vs/base/common/resources'; import { NotebookFindContrib } from 'vs/workbench/contrib/notebook/browser/contrib/find/notebookFindWidget'; import { INTERACTIVE_WINDOW_EDITOR_ID } from 'vs/workbench/contrib/notebook/common/notebookCommon'; import 'vs/css!./interactiveEditor'; +import { IEditorOptions } from 'vs/editor/common/config/editorOptions'; +import { deepClone } from 'vs/base/common/objects'; const DECORATION_KEY = 'interactiveInputDecoration'; const INTERACTIVE_EDITOR_VIEW_STATE_PREFERENCE_KEY = 'InteractiveEditorViewState'; @@ -93,6 +95,7 @@ export class InteractiveEditor extends EditorPane { #instantiationService: IInstantiationService; #languageService: ILanguageService; #contextKeyService: IContextKeyService; + #configurationService: IConfigurationService; #notebookKernelService: INotebookKernelService; #keybindingService: IKeybindingService; #menuService: IMenuService; @@ -102,6 +105,7 @@ export class InteractiveEditor extends EditorPane { #extensionService: IExtensionService; #widgetDisposableStore: DisposableStore = this._register(new DisposableStore()); #lastLayoutDimensions?: { readonly dimension: DOM.Dimension; readonly position: DOM.IDomPosition }; + #editorOptions: IEditorOptions; #notebookOptions: NotebookOptions; #editorMemento: IEditorMemento; #groupListener = this._register(new DisposableStore()); @@ -123,7 +127,7 @@ export class InteractiveEditor extends EditorPane { @INotebookKernelService notebookKernelService: INotebookKernelService, @ILanguageService languageService: ILanguageService, @IKeybindingService keybindingService: IKeybindingService, - @IConfigurationService private configurationService: IConfigurationService, + @IConfigurationService configurationService: IConfigurationService, @IMenuService menuService: IMenuService, @IContextMenuService contextMenuService: IContextMenuService, @IEditorGroupsService editorGroupService: IEditorGroupsService, @@ -140,6 +144,7 @@ export class InteractiveEditor extends EditorPane { this.#instantiationService = instantiationService; this.#notebookWidgetService = notebookWidgetService; this.#contextKeyService = contextKeyService; + this.#configurationService = configurationService; this.#notebookKernelService = notebookKernelService; this.#languageService = languageService; this.#keybindingService = keybindingService; @@ -149,6 +154,12 @@ export class InteractiveEditor extends EditorPane { this.#notebookExecutionStateService = notebookExecutionStateService; this.#extensionService = extensionService; + this.#editorOptions = this.#computeEditorOptions(); + this._register(this.#configurationService.onDidChangeConfiguration(e => { + if (e.affectsConfiguration('editor') || e.affectsConfiguration('notebook')) { + this.#editorOptions = this.#computeEditorOptions(); + } + })); this.#notebookOptions = new NotebookOptions(configurationService, notebookExecutionStateService, true, { cellToolbarInteraction: 'hover', globalToolbar: true, dragAndDropEnabled: false }); this.#editorMemento = this.getEditorMemento(editorGroupService, textResourceConfigurationService, INTERACTIVE_EDITOR_VIEW_STATE_PREFERENCE_KEY); @@ -259,6 +270,31 @@ export class InteractiveEditor extends EditorPane { this.#styleElement.textContent = styleSheets.join('\n'); } + #computeEditorOptions(): IEditorOptions { + let overrideIdentifier: string | undefined = undefined; + if (this.#codeEditorWidget) { + overrideIdentifier = this.#codeEditorWidget.getModel()?.getLanguageId(); + } + const editorOptions = deepClone(this.#configurationService.getValue('editor', { overrideIdentifier })); + const editorOptionsOverride = getSimpleEditorOptions(); + const computed = Object.freeze({ + ...editorOptions, + ...editorOptionsOverride, + ...{ + glyphMargin: true, + padding: { + top: INPUT_EDITOR_PADDING, + bottom: INPUT_EDITOR_PADDING + }, + hover: { + enabled: true + } + } + }); + + return computed; + } + protected override saveState(): void { this.#saveEditorViewState(this.input); super.saveState(); @@ -350,19 +386,7 @@ export class InteractiveEditor extends EditorPane { options: this.#notebookOptions }); - this.#codeEditorWidget = this.#instantiationService.createInstance(CodeEditorWidget, this.#inputEditorContainer, { - ...getSimpleEditorOptions(), - ...{ - glyphMargin: true, - padding: { - top: INPUT_EDITOR_PADDING, - bottom: INPUT_EDITOR_PADDING - }, - hover: { - enabled: true - } - } - }, { + this.#codeEditorWidget = this.#instantiationService.createInstance(CodeEditorWidget, this.#inputEditorContainer, this.#editorOptions, { ...{ isSimpleWidget: false, contributions: EditorExtensionsRegistry.getSomeEditorContributions([ @@ -438,6 +462,8 @@ export class InteractiveEditor extends EditorPane { if (viewState?.input) { this.#codeEditorWidget.restoreViewState(viewState.input); } + this.#editorOptions = this.#computeEditorOptions(); + this.#codeEditorWidget.updateOptions(this.#editorOptions); this.#widgetDisposableStore.add(this.#codeEditorWidget.onDidFocusEditorWidget(() => this.#onDidFocusWidget.fire())); this.#widgetDisposableStore.add(this.#codeEditorWidget.onDidContentSizeChange(e => { @@ -536,7 +562,7 @@ export class InteractiveEditor extends EditorPane { const index = this.#notebookWidget.value!.getCellIndex(cvm); if (index === this.#notebookWidget.value!.getLength() - 1) { // If we're already at the bottom or auto scroll is enabled, scroll to the bottom - if (this.configurationService.getValue(InteractiveWindowSetting.interactiveWindowAlwaysScrollOnNewCell) || this.#cellAtBottom(cvm)) { + if (this.#configurationService.getValue(InteractiveWindowSetting.interactiveWindowAlwaysScrollOnNewCell) || this.#cellAtBottom(cvm)) { this.#notebookWidget.value!.scrollToBottom(); } }