Skip to content

Commit 46b7e7b

Browse files
authored
Merge pull request microsoft#181949 from r3m0t/interactive-window-compact-b
Interactive window- don't leave space for insert toolbar
2 parents d3d9f86 + 2e440e1 commit 46b7e7b

File tree

8 files changed

+31
-12
lines changed

8 files changed

+31
-12
lines changed

src/vs/workbench/contrib/interactive/browser/interactiveEditor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ export class InteractiveEditor extends EditorPane {
148148
this.#notebookExecutionStateService = notebookExecutionStateService;
149149
this.#extensionService = extensionService;
150150

151-
this.#notebookOptions = new NotebookOptions(configurationService, notebookExecutionStateService, { cellToolbarInteraction: 'hover', globalToolbar: true, dragAndDropEnabled: false });
151+
this.#notebookOptions = new NotebookOptions(configurationService, notebookExecutionStateService, true, { cellToolbarInteraction: 'hover', globalToolbar: true, dragAndDropEnabled: false });
152152
this.#editorMemento = this.getEditorMemento<InteractiveEditorViewState>(editorGroupService, textResourceConfigurationService, INTERACTIVE_EDITOR_VIEW_STATE_PREFERENCE_KEY);
153153

154154
codeEditorService.registerDecorationType('interactive-decoration', DECORATION_KEY, {});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export class NotebookTextDiffEditor extends EditorPane implements INotebookTextD
151151
@INotebookExecutionStateService notebookExecutionStateService: INotebookExecutionStateService,
152152
) {
153153
super(NotebookTextDiffEditor.ID, telemetryService, themeService, storageService);
154-
this._notebookOptions = new NotebookOptions(this.configurationService, notebookExecutionStateService);
154+
this._notebookOptions = new NotebookOptions(this.configurationService, notebookExecutionStateService, false);
155155
this._register(this._notebookOptions);
156156
const editorOptions = this.configurationService.getValue<ICodeEditorOptions>('editor');
157157
this._fontInfo = FontMeasurements.readFontInfo(BareFontInfo.createFromRawSettings(editorOptions, PixelRatio.value));

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD
292292
this.isEmbedded = creationOptions.isEmbedded ?? false;
293293
this._readOnly = creationOptions.isReadOnly ?? false;
294294

295-
this._notebookOptions = creationOptions.options ?? new NotebookOptions(this.configurationService, notebookExecutionStateService);
295+
this._notebookOptions = creationOptions.options ?? new NotebookOptions(this.configurationService, notebookExecutionStateService, this._readOnly);
296296
this._register(this._notebookOptions);
297297
this._viewContext = new ViewContext(
298298
this._notebookOptions,
@@ -1176,6 +1176,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD
11761176
}
11771177

11781178
this.viewModel.updateOptions({ isReadOnly: this._readOnly });
1179+
this.notebookOptions.updateOptions(this._readOnly);
11791180

11801181
// reveal cell if editor options tell to do so
11811182
const cellOptions = options?.cellOptions ?? this._parseIndexedCellOptions(options);
@@ -1364,6 +1365,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD
13641365

13651366
this.viewModel = this.instantiationService.createInstance(NotebookViewModel, textModel.viewType, textModel, this._viewContext, this.getLayoutInfo(), { isReadOnly: this._readOnly });
13661367
this._viewContext.eventDispatcher.emit([new NotebookLayoutChangedEvent({ width: true, fontInfo: true }, this.getLayoutInfo())]);
1368+
this.notebookOptions.updateOptions(this._readOnly);
13671369

13681370
this._updateForOptions();
13691371
this._updateForNotebookConfiguration();

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

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ export class NotebookOptions extends Disposable {
133133
constructor(
134134
private readonly configurationService: IConfigurationService,
135135
private readonly notebookExecutionStateService: INotebookExecutionStateService,
136+
private isReadonly: boolean,
136137
private readonly overrides?: { cellToolbarInteraction: string; globalToolbar: boolean; dragAndDropEnabled: boolean }
137138
) {
138139
super();
@@ -145,7 +146,7 @@ export class NotebookOptions extends Disposable {
145146
const cellToolbarInteraction = overrides?.cellToolbarInteraction ?? this.configurationService.getValue<string>(NotebookSetting.cellToolbarVisibility);
146147
const compactView = this.configurationService.getValue<boolean | undefined>(NotebookSetting.compactView) ?? true;
147148
const focusIndicator = this._computeFocusIndicatorOption();
148-
const insertToolbarPosition = this._computeInsertToolbarPositionOption();
149+
const insertToolbarPosition = this._computeInsertToolbarPositionOption(this.isReadonly);
149150
const insertToolbarAlignment = this._computeInsertToolbarAlignmentOption();
150151
const showFoldingControls = this._computeShowFoldingControlsOption();
151152
// const { bottomToolbarGap, bottomToolbarHeight } = this._computeBottomToolbarDimensions(compactView, insertToolbarPosition, insertToolbarAlignment);
@@ -248,6 +249,22 @@ export class NotebookOptions extends Disposable {
248249
}));
249250
}
250251

252+
updateOptions(isReadonly: boolean) {
253+
if (this.isReadonly !== isReadonly) {
254+
this.isReadonly = isReadonly;
255+
256+
this._updateConfiguration({
257+
affectsConfiguration(configuration: string): boolean {
258+
return configuration === NotebookSetting.insertToolbarLocation;
259+
},
260+
source: ConfigurationTarget.DEFAULT,
261+
affectedKeys: new Set([NotebookSetting.insertToolbarLocation]),
262+
change: { keys: [NotebookSetting.insertToolbarLocation], overrides: [] },
263+
sourceConfig: undefined
264+
});
265+
}
266+
}
267+
251268
private _migrateDeprecatedSetting(deprecatedKey: string, key: string): void {
252269
const deprecatedSetting = this.configurationService.inspect(deprecatedKey);
253270

@@ -390,7 +407,7 @@ export class NotebookOptions extends Disposable {
390407
}
391408

392409
if (insertToolbarPosition) {
393-
configuration.insertToolbarPosition = this._computeInsertToolbarPositionOption();
410+
configuration.insertToolbarPosition = this._computeInsertToolbarPositionOption(this.isReadonly);
394411
}
395412

396413
if (globalToolbar && this.overrides?.globalToolbar === undefined) {
@@ -479,8 +496,8 @@ export class NotebookOptions extends Disposable {
479496
});
480497
}
481498

482-
private _computeInsertToolbarPositionOption() {
483-
return this.configurationService.getValue<'betweenCells' | 'notebookToolbar' | 'both' | 'hidden'>(NotebookSetting.insertToolbarLocation) ?? 'both';
499+
private _computeInsertToolbarPositionOption(isReadOnly: boolean) {
500+
return isReadOnly ? 'hidden' : this.configurationService.getValue<'betweenCells' | 'notebookToolbar' | 'both' | 'hidden'>(NotebookSetting.insertToolbarLocation) ?? 'both';
484501
}
485502

486503
private _computeInsertToolbarAlignmentOption() {

src/vs/workbench/contrib/notebook/browser/viewModel/codeCellViewModel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ export class CodeCellViewModel extends BaseCellViewModel implements ICellViewMod
202202
// recompute
203203
this._ensureOutputsTop();
204204
const notebookLayoutConfiguration = this.viewContext.notebookOptions.getLayoutConfiguration();
205-
const bottomToolbarDimensions = this.viewContext.notebookOptions.computeBottomToolbarDimensions();
205+
const bottomToolbarDimensions = this.viewContext.notebookOptions.computeBottomToolbarDimensions(this.viewType);
206206
const outputShowMoreContainerHeight = state.outputShowMoreContainerHeight ? state.outputShowMoreContainerHeight : this._layoutInfo.outputShowMoreContainerHeight;
207207
const outputTotalHeight = Math.max(this._outputMinHeight, this.isOutputCollapsed ? notebookLayoutConfiguration.collapsedIndicatorHeight : this._outputsTop!.getTotalSum());
208208
const commentHeight = state.commentHeight ? this._commentHeight : this._layoutInfo.commentHeight;

src/vs/workbench/contrib/notebook/test/browser/notebookCellList.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ suite('NotebookCellList', () => {
2121
suiteSetup(() => {
2222
disposables = new DisposableStore();
2323
instantiationService = setupInstantiationService(disposables);
24-
notebookDefaultOptions = new NotebookOptions(instantiationService.get(IConfigurationService), instantiationService.get(INotebookExecutionStateService));
24+
notebookDefaultOptions = new NotebookOptions(instantiationService.get(IConfigurationService), instantiationService.get(INotebookExecutionStateService), false);
2525
topInsertToolbarHeight = notebookDefaultOptions.computeTopInsertToolbarHeight();
2626

2727
});

src/vs/workbench/contrib/notebook/test/browser/notebookViewModel.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ suite('NotebookViewModel', () => {
5858
test('ctor', function () {
5959
const notebook = new NotebookTextModel('notebook', URI.parse('test'), [], {}, { transientCellMetadata: {}, transientDocumentMetadata: {}, transientOutputs: false, cellContentMetadata: {} }, undoRedoService, modelService, languageService);
6060
const model = new NotebookEditorTestModel(notebook);
61-
const viewContext = new ViewContext(new NotebookOptions(instantiationService.get(IConfigurationService), instantiationService.get(INotebookExecutionStateService)), new NotebookEventDispatcher(), () => ({} as IBaseCellEditorOptions));
61+
const viewContext = new ViewContext(new NotebookOptions(instantiationService.get(IConfigurationService), instantiationService.get(INotebookExecutionStateService), false), new NotebookEventDispatcher(), () => ({} as IBaseCellEditorOptions));
6262
const viewModel = new NotebookViewModel('notebook', model.notebook, viewContext, null, { isReadOnly: false }, instantiationService, bulkEditService, undoRedoService, textModelService, notebookExecutionStateService);
6363
assert.strictEqual(viewModel.viewType, 'notebook');
6464
});

src/vs/workbench/contrib/notebook/test/browser/testNotebookEditor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ function _createTestNotebookEditor(instantiationService: TestInstantiationServic
201201
}), {}, { transientCellMetadata: {}, transientDocumentMetadata: {}, cellContentMetadata: {}, transientOutputs: false });
202202

203203
const model = new NotebookEditorTestModel(notebook);
204-
const notebookOptions = new NotebookOptions(instantiationService.get(IConfigurationService), instantiationService.get(INotebookExecutionStateService));
204+
const notebookOptions = new NotebookOptions(instantiationService.get(IConfigurationService), instantiationService.get(INotebookExecutionStateService), false);
205205
const viewContext = new ViewContext(notebookOptions, new NotebookEventDispatcher(), () => ({} as IBaseCellEditorOptions));
206206
const viewModel: NotebookViewModel = instantiationService.createInstance(NotebookViewModel, viewType, model.notebook, viewContext, null, { isReadOnly: false });
207207

@@ -374,7 +374,7 @@ export function createNotebookCellList(instantiationService: TestInstantiationSe
374374
NotebookCellList,
375375
'NotebookCellList',
376376
DOM.$('container'),
377-
viewContext ?? new ViewContext(new NotebookOptions(instantiationService.get(IConfigurationService), instantiationService.get(INotebookExecutionStateService)), new NotebookEventDispatcher(), () => ({} as IBaseCellEditorOptions)),
377+
viewContext ?? new ViewContext(new NotebookOptions(instantiationService.get(IConfigurationService), instantiationService.get(INotebookExecutionStateService), false), new NotebookEventDispatcher(), () => ({} as IBaseCellEditorOptions)),
378378
delegate,
379379
[renderer],
380380
instantiationService.get<IContextKeyService>(IContextKeyService),

0 commit comments

Comments
 (0)