Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/vs/workbench/browser/parts/editor/editorStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,12 @@ class EditorStatus extends Disposable {
return;
}

const editorURI = getCodeEditor(this.editorService.activeTextEditorControl)?.getModel()?.uri;
if (editorURI?.scheme === Schemas.vscodeNotebookCell) {
this.selectionElement.clear();
return;
}

const props: IStatusbarEntry = {
name: localize('status.editor.selection', "Editor Selection"),
text,
Expand All @@ -466,6 +472,12 @@ class EditorStatus extends Disposable {
return;
}

const editorURI = getCodeEditor(this.editorService.activeTextEditorControl)?.getModel()?.uri;
if (editorURI?.scheme === Schemas.vscodeNotebookCell) {
this.indentationElement.clear();
return;
}

const props: IStatusbarEntry = {
name: localize('status.editor.indentation', "Editor Indentation"),
text,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ import { Disposable, DisposableStore, IDisposable, MutableDisposable } from 'vs/
import { Schemas } from 'vs/base/common/network';
import { ILanguageFeaturesService } from 'vs/editor/common/services/languageFeatures';
import * as nls from 'vs/nls';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { ILogService } from 'vs/platform/log/common/log';
import { Registry } from 'vs/platform/registry/common/platform';
import { Extensions as WorkbenchExtensions, IWorkbenchContribution, IWorkbenchContributionsRegistry } from 'vs/workbench/common/contributions';
import { Extensions as WorkbenchExtensions, IWorkbenchContribution, IWorkbenchContributionsRegistry, registerWorkbenchContribution2, WorkbenchPhase } from 'vs/workbench/common/contributions';
import { CENTER_ACTIVE_CELL } from 'vs/workbench/contrib/notebook/browser/contrib/navigation/arrow';
import { SELECT_KERNEL_ID } from 'vs/workbench/contrib/notebook/browser/controller/coreActions';
// import { SELECT_NOTEBOOK_INDENTATION_ID } from 'vs/workbench/contrib/notebook/browser/controller/editActions';
import { getNotebookEditorFromEditorPane, INotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel';
import { NotebookCellsChangeType } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { NotebookCellsChangeType, NotebookSetting } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { INotebookKernel, INotebookKernelService } from 'vs/workbench/contrib/notebook/common/notebookKernelService';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle';
Expand Down Expand Up @@ -254,3 +256,79 @@ export class ActiveCellStatus extends Disposable implements IWorkbenchContributi
}

Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench).registerWorkbenchContribution(ActiveCellStatus, LifecyclePhase.Restored);

export class NotebookIndentationStatus extends Disposable implements IWorkbenchContribution {

private readonly _itemDisposables = this._register(new DisposableStore());
private readonly _accessor = this._register(new MutableDisposable<IStatusbarEntryAccessor>());

static readonly ID = 'selectNotebookIndentation';

constructor(
@IEditorService private readonly _editorService: IEditorService,
@IStatusbarService private readonly _statusbarService: IStatusbarService,
@IConfigurationService private readonly _configurationService: IConfigurationService,
) {
super();
this._register(this._editorService.onDidActiveEditorChange(() => this._update()));
this._register(this._configurationService.onDidChangeConfiguration(e => {
if (e.affectsConfiguration('editor') || e.affectsConfiguration('notebook')) {
this._update();
}
}));
}

private _update() {
this._itemDisposables.clear();
const activeEditor = getNotebookEditorFromEditorPane(this._editorService.activeEditorPane);
if (activeEditor) {
this._show(activeEditor);
} else {
this._accessor.clear();
}
}

private _show(editor: INotebookEditor) {
if (!editor.hasModel()) {
this._accessor.clear();
return;
}

const cellEditorOverrides = this._configurationService.getValue(NotebookSetting.cellEditorOptionsCustomizations) as any;

const indentSize = cellEditorOverrides['editor.indentSize'] ?? this._configurationService.getValue('editor.indentSize');
const tabSize = cellEditorOverrides['editor.tabSize'] ?? this._configurationService.getValue('editor.tabSize');
const insertSpaces = cellEditorOverrides['editor.insertSpaces'] ?? this._configurationService.getValue('editor.insertSpaces');

const width = typeof indentSize === 'number' ? indentSize : tabSize;

const message = insertSpaces ? `Spaces: ${width}` : `Tab Size: ${width}`;
const newText = message;
if (!newText) {
this._accessor.clear();
return;
}

const entry: IStatusbarEntry = {
name: nls.localize('notebook.indentation', "Notebook Indentation"),
text: newText,
ariaLabel: newText,
// tooltip: nls.localize('selectNotebookIndentation', "Select Notebook Indentation"),
tooltip: nls.localize('selectNotebookIndentation', "Notebook Indentation"),
// command: SELECT_NOTEBOOK_INDENTATION_ID // TODO@Yoyokrazy -- finish hooking this up
};

if (!this._accessor.value) {
this._accessor.value = this._statusbarService.addEntry(
entry,
'notebook.status.indentation',
StatusbarAlignment.RIGHT,
100.4
);
} else {
this._accessor.value.update(entry);
}
}
}

registerWorkbenchContribution2(NotebookIndentationStatus.ID, NotebookIndentationStatus, WorkbenchPhase.AfterRestored); // TODO@Yoyokrazy -- unsure on the phase
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const CLEAR_ALL_CELLS_OUTPUTS_COMMAND_ID = 'notebook.clearAllCellsOutputs';
const EDIT_CELL_COMMAND_ID = 'notebook.cell.edit';
const DELETE_CELL_COMMAND_ID = 'notebook.cell.delete';
export const CLEAR_CELL_OUTPUTS_COMMAND_ID = 'notebook.cell.clearOutputs';
export const SELECT_NOTEBOOK_INDENTATION_ID = 'notebook.selectIndentation';

registerAction2(class EditCellAction extends NotebookCellAction {
constructor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const SCROLLABLE_ELEMENT_PADDING_TOP = 18;

export const OutputInnerContainerTopPadding = 4;

export interface NotebookDisplayOptions {
export interface NotebookDisplayOptions { // TODO @Yoyokrazy rename to a more generic name, not display
showCellStatusBar: ShowCellStatusBarType;
cellToolbarLocation: string | { [key: string]: string };
cellToolbarInteraction: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,56 @@ import { CellContentPart } from 'vs/workbench/contrib/notebook/browser/view/cell
import { NotebookCellInternalMetadata, NOTEBOOK_EDITOR_ID } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { NotebookOptions } from 'vs/workbench/contrib/notebook/browser/notebookOptions';
import { CellViewModelStateChangeEvent } from 'vs/workbench/contrib/notebook/browser/notebookViewEvents';
import { ITextModelUpdateOptions } from 'vs/editor/common/model';

export class CellEditorOptions extends CellContentPart {
//todo@Yoyokrazy implenets is needed or not?
export class CellEditorOptions extends CellContentPart implements ITextModelUpdateOptions {
private _lineNumbers: 'on' | 'off' | 'inherit' = 'inherit';
private _tabSize?: number;
private _indentSize?: number | 'tabSize';
private _insertSpaces?: boolean;

set tabSize(value: number | undefined) {
if (this._tabSize !== value) {
this._tabSize = value;
this._onDidChange.fire();
}
}

get tabSize() {
return this._tabSize;
}

set indentSize(value: number | 'tabSize' | undefined) {
if (this._indentSize !== value) {
this._indentSize = value;
this._onDidChange.fire();
}
}

get indentSize() {
return this._indentSize;
}

set insertSpaces(value: boolean | undefined) {
if (this._insertSpaces !== value) {
this._insertSpaces = value;
this._onDidChange.fire();
}
}

get insertSpaces() {
return this._insertSpaces;
}

private readonly _onDidChange = this._register(new Emitter<void>());
readonly onDidChange: Event<void> = this._onDidChange.event;
private _value: IEditorOptions;

constructor(private readonly base: IBaseCellEditorOptions, readonly notebookOptions: NotebookOptions, readonly configurationService: IConfigurationService) {
constructor(
private readonly base: IBaseCellEditorOptions,
readonly notebookOptions: NotebookOptions,
readonly configurationService: IConfigurationService) {
super();

this._register(base.onDidChange(() => {
Expand All @@ -50,7 +92,23 @@ export class CellEditorOptions extends CellContentPart {
}

private _computeEditorOptions() {
const value = this.base.value;
const value = this.base.value; // base IEditorOptions

// TODO @Yoyokrazy find a different way to get the editor overrides, this is not the right way
const cellEditorOverridesRaw = this.notebookOptions.getDisplayOptions().editorOptionsCustomizations;
const indentSize = cellEditorOverridesRaw['editor.indentSize'];
if (indentSize !== undefined) {
this.indentSize = indentSize;
}
const insertSpaces = cellEditorOverridesRaw['editor.insertSpaces'];
if (insertSpaces !== undefined) {
this.insertSpaces = insertSpaces;
}
const tabSize = cellEditorOverridesRaw['editor.tabSize'];
if (tabSize !== undefined) {
this.tabSize = tabSize;
}

let cellRenderLineNumber = value.lineNumbers;

switch (this._lineNumbers) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export class CodeCell extends Disposable {
private readonly cellParts: CellPartsCollection;

private _collapsedExecutionIcon: CollapsedCodeCellExecutionIcon;
private _cellEditorOptions: CellEditorOptions;

constructor(
private readonly notebookEditor: IActiveNotebookEditorDelegate,
Expand All @@ -52,13 +53,13 @@ export class CodeCell extends Disposable {
@IOpenerService openerService: IOpenerService,
@ILanguageService private readonly languageService: ILanguageService,
@IConfigurationService private configurationService: IConfigurationService,
@INotebookExecutionStateService notebookExecutionStateService: INotebookExecutionStateService
@INotebookExecutionStateService notebookExecutionStateService: INotebookExecutionStateService,
) {
super();

const cellEditorOptions = this._register(new CellEditorOptions(this.notebookEditor.getBaseCellEditorOptions(viewCell.language), this.notebookEditor.notebookOptions, this.configurationService));
this._cellEditorOptions = this._register(new CellEditorOptions(this.notebookEditor.getBaseCellEditorOptions(viewCell.language), this.notebookEditor.notebookOptions, this.configurationService));
this._outputContainerRenderer = this.instantiationService.createInstance(CellOutputContainer, notebookEditor, viewCell, templateData, { limit: outputDisplayLimit });
this.cellParts = this._register(templateData.cellParts.concatContentPart([cellEditorOptions, this._outputContainerRenderer], DOM.getWindow(notebookEditor.getDomNode())));
this.cellParts = this._register(templateData.cellParts.concatContentPart([this._cellEditorOptions, this._outputContainerRenderer], DOM.getWindow(notebookEditor.getDomNode())));

// this.viewCell.layoutInfo.editorHeight or estimation when this.viewCell.layoutInfo.editorHeight === 0
const editorHeight = this.calculateInitEditorHeight();
Expand Down Expand Up @@ -135,9 +136,29 @@ export class CodeCell extends Disposable {
this._register(Event.runAndSubscribe(viewCell.onDidChangeOutputs, this.updateForOutputs.bind(this)));
this._register(Event.runAndSubscribe(viewCell.onDidChangeLayout, this.updateForLayout.bind(this)));

cellEditorOptions.setLineNumbers(this.viewCell.lineNumbers);
this._register(cellEditorOptions.onDidChange(() => templateData.editor.updateOptions(cellEditorOptions.getUpdatedValue(this.viewCell.internalMetadata, this.viewCell.uri))));
templateData.editor.updateOptions(cellEditorOptions.getUpdatedValue(this.viewCell.internalMetadata, this.viewCell.uri));
this._cellEditorOptions.setLineNumbers(this.viewCell.lineNumbers);
this._register(this._cellEditorOptions.onDidChange(() => this.updateCodeCellOptions(templateData)));
templateData.editor.updateOptions(this._cellEditorOptions.getUpdatedValue(this.viewCell.internalMetadata, this.viewCell.uri));
}

private updateCodeCellOptions(templateData: CodeCellRenderTemplate) {
templateData.editor.updateOptions(this._cellEditorOptions.getUpdatedValue(this.viewCell.internalMetadata, this.viewCell.uri));

const cts = new CancellationTokenSource();
this._register({ dispose() { cts.dispose(true); } });
raceCancellation(this.viewCell.resolveTextModel(), cts.token).then(model => {
if (this._isDisposed) {
return;
}

if (model) {
Comment thread
Yoyokrazy marked this conversation as resolved.
Resolved
model.updateOptions({
indentSize: this._cellEditorOptions.indentSize,
tabSize: this._cellEditorOptions.tabSize,
insertSpaces: this._cellEditorOptions.insertSpaces,
});
}
});
}

private _pendingLayout: IDisposable | undefined;
Expand Down Expand Up @@ -186,6 +207,11 @@ export class CodeCell extends Disposable {
if (model && this.templateData.editor) {
this._reigsterModelListeners(model);
this.templateData.editor.setModel(model);
model.updateOptions({
indentSize: this._cellEditorOptions.indentSize,
tabSize: this._cellEditorOptions.tabSize,
insertSpaces: this._cellEditorOptions.insertSpaces,
});
this.viewCell.attachTextEditor(this.templateData.editor, this.viewCell.layoutInfo.estimatedHasHorizontalScrolling);
const focusEditorIfNeeded = () => {
if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export class MarkupCell extends Disposable {
private foldingState: CellFoldingState;
private cellEditorOptions: CellEditorOptions;
private editorOptions: IEditorOptions;
private _isDisposed: boolean = false;

constructor(
private readonly notebookEditor: IActiveNotebookEditorDelegate,
Expand Down Expand Up @@ -174,9 +175,31 @@ export class MarkupCell extends Disposable {
}
}));

this._register(this.cellEditorOptions.onDidChange(() => {
this.updateEditorOptions(this.cellEditorOptions.getUpdatedValue(this.viewCell.internalMetadata, this.viewCell.uri));
}));
this._register(this.cellEditorOptions.onDidChange(() => this.updateMarkupCellOptions()));
}

private updateMarkupCellOptions(): any {
this.updateEditorOptions(this.cellEditorOptions.getUpdatedValue(this.viewCell.internalMetadata, this.viewCell.uri));

if (this.editor) {
this.editor.updateOptions(this.cellEditorOptions.getUpdatedValue(this.viewCell.internalMetadata, this.viewCell.uri));

const cts = new CancellationTokenSource();
this._register({ dispose() { cts.dispose(true); } });
raceCancellation(this.viewCell.resolveTextModel(), cts.token).then(model => {
if (this._isDisposed) {
return;
}

if (model) {
Comment thread
Yoyokrazy marked this conversation as resolved.
Resolved
model.updateOptions({
indentSize: this.cellEditorOptions.indentSize,
tabSize: this.cellEditorOptions.tabSize,
insertSpaces: this.cellEditorOptions.insertSpaces,
});
}
});
}
}

private updateCollapsedState() {
Expand Down Expand Up @@ -223,6 +246,8 @@ export class MarkupCell extends Disposable {
}

override dispose() {
this._isDisposed = true;

// move focus back to the cell list otherwise the focus goes to body
if (this.notebookEditor.getActiveCell() === this.viewCell && this.viewCell.focusMode === CellFocusMode.Editor && (this.notebookEditor.hasEditorFocus() || this.notebookEditor.getDomNode().ownerDocument.activeElement === this.notebookEditor.getDomNode().ownerDocument.body)) {
this.notebookEditor.focusContainer();
Expand Down Expand Up @@ -354,6 +379,11 @@ export class MarkupCell extends Disposable {
}

this.editor!.setModel(model);
model.updateOptions({
indentSize: this.cellEditorOptions.indentSize,
tabSize: this.cellEditorOptions.tabSize,
insertSpaces: this.cellEditorOptions.insertSpaces,
});

const realContentHeight = this.editor!.getContentHeight();
if (realContentHeight !== editorHeight) {
Expand Down