Add "show cell breakpoint margin" command
This commit is contained in:
parent
0297ae8de1
commit
fcf6cec4f9
4 changed files with 58 additions and 15 deletions
|
@ -52,6 +52,7 @@ export const NOTEBOOK_OUTPUT_FOCUSED = new RawContextKey<boolean>('notebookOutpu
|
|||
export const NOTEBOOK_EDITOR_EDITABLE = new RawContextKey<boolean>('notebookEditable', true);
|
||||
export const NOTEBOOK_HAS_RUNNING_CELL = new RawContextKey<boolean>('notebookHasRunningCell', false);
|
||||
export const NOTEBOOK_USE_CONSOLIDATED_OUTPUT_BUTTON = new RawContextKey<boolean>('notebookUseConsolidatedOutputButton', false);
|
||||
export const NOTEBOOK_BREAKPOINT_MARGIN_ACTIVE = new RawContextKey<boolean>('notebookBreakpointMargin', false);
|
||||
|
||||
// Cell keys
|
||||
export const NOTEBOOK_VIEW_TYPE = new RawContextKey<string>('notebookType', undefined);
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
import { DisposableStore, dispose, IDisposable } from 'vs/base/common/lifecycle';
|
||||
import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { ICellViewModel, INotebookEditor, NOTEBOOK_HAS_OUTPUTS, NOTEBOOK_HAS_RUNNING_CELL, NOTEBOOK_INTERRUPTIBLE_KERNEL, NOTEBOOK_KERNEL_COUNT, NOTEBOOK_KERNEL_SELECTED, NOTEBOOK_USE_CONSOLIDATED_OUTPUT_BUTTON, NOTEBOOK_VIEW_TYPE } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
|
||||
import { ICellViewModel, INotebookEditor, NOTEBOOK_BREAKPOINT_MARGIN_ACTIVE, NOTEBOOK_HAS_OUTPUTS, NOTEBOOK_HAS_RUNNING_CELL, NOTEBOOK_INTERRUPTIBLE_KERNEL, NOTEBOOK_KERNEL_COUNT, NOTEBOOK_KERNEL_SELECTED, NOTEBOOK_USE_CONSOLIDATED_OUTPUT_BUTTON, NOTEBOOK_VIEW_TYPE } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
|
||||
import { CellViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel';
|
||||
import { NotebookCellExecutionState } from 'vs/workbench/contrib/notebook/common/notebookCommon';
|
||||
import { INotebookKernelService } from 'vs/workbench/contrib/notebook/common/notebookKernelService';
|
||||
|
@ -18,6 +18,7 @@ export class NotebookEditorContextKeys {
|
|||
private readonly _someCellRunning: IContextKey<boolean>;
|
||||
private readonly _hasOutputs: IContextKey<boolean>;
|
||||
private readonly _useConsolidatedOutputButton: IContextKey<boolean>;
|
||||
private readonly _breakpointMarginActive: IContextKey<boolean>;
|
||||
private _viewType!: IContextKey<string>;
|
||||
|
||||
private readonly _disposables = new DisposableStore();
|
||||
|
@ -35,6 +36,7 @@ export class NotebookEditorContextKeys {
|
|||
this._interruptibleKernel = NOTEBOOK_INTERRUPTIBLE_KERNEL.bindTo(contextKeyService);
|
||||
this._someCellRunning = NOTEBOOK_HAS_RUNNING_CELL.bindTo(contextKeyService);
|
||||
this._useConsolidatedOutputButton = NOTEBOOK_USE_CONSOLIDATED_OUTPUT_BUTTON.bindTo(contextKeyService);
|
||||
this._breakpointMarginActive = NOTEBOOK_BREAKPOINT_MARGIN_ACTIVE.bindTo(contextKeyService);
|
||||
this._hasOutputs = NOTEBOOK_HAS_OUTPUTS.bindTo(contextKeyService);
|
||||
this._viewType = NOTEBOOK_VIEW_TYPE.bindTo(contextKeyService);
|
||||
|
||||
|
@ -145,6 +147,8 @@ export class NotebookEditorContextKeys {
|
|||
}
|
||||
|
||||
private _updateForNotebookOptions(): void {
|
||||
this._useConsolidatedOutputButton.set(this._editor.notebookOptions.getLayoutConfiguration().consolidatedOutputButton);
|
||||
const layout = this._editor.notebookOptions.getLayoutConfiguration();
|
||||
this._useConsolidatedOutputButton.set(layout.consolidatedOutputButton);
|
||||
this._breakpointMarginActive.set(layout.cellBreakpointMarginActive);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,13 +10,13 @@ import { Registry } from 'vs/platform/registry/common/platform';
|
|||
import { IConfigurationRegistry, Extensions as ConfigurationExtensions } from 'vs/platform/configuration/common/configurationRegistry';
|
||||
import { IEditorOptions, LineNumbersType } from 'vs/editor/common/config/editorOptions';
|
||||
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
||||
import { getNotebookEditorFromEditorPane, ICellViewModel, INotebookEditor, NOTEBOOK_CELL_LINE_NUMBERS, NOTEBOOK_EDITOR_FOCUSED, NOTEBOOK_IS_ACTIVE_EDITOR } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
|
||||
import { getNotebookEditorFromEditorPane, ICellViewModel, INotebookEditor, NOTEBOOK_BREAKPOINT_MARGIN_ACTIVE, NOTEBOOK_CELL_LINE_NUMBERS, NOTEBOOK_EDITOR_FOCUSED, NOTEBOOK_IS_ACTIVE_EDITOR } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
|
||||
import { localize } from 'vs/nls';
|
||||
import { Action2, MenuId, registerAction2 } from 'vs/platform/actions/common/actions';
|
||||
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
|
||||
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { NOTEBOOK_ACTIONS_CATEGORY } from 'vs/workbench/contrib/notebook/browser/contrib/coreActions';
|
||||
import { INotebookActionContext, NotebookAction, NOTEBOOK_ACTIONS_CATEGORY } from 'vs/workbench/contrib/notebook/browser/contrib/coreActions';
|
||||
import { NotebookOptions } from 'vs/workbench/contrib/notebook/common/notebookOptions';
|
||||
import { NotebookCellInternalMetadata } from 'vs/workbench/contrib/notebook/common/notebookCommon';
|
||||
|
||||
|
@ -58,7 +58,7 @@ export class CellEditorOptions extends Disposable {
|
|||
}));
|
||||
|
||||
this._register(notebookOptions.onDidChangeOptions(e => {
|
||||
if (e.cellStatusBarVisibility || e.editorTopPadding || e.editorOptionsCustomizations) {
|
||||
if (e.cellStatusBarVisibility || e.editorTopPadding || e.editorOptionsCustomizations || e.cellBreakpointMargin) {
|
||||
this._recomputeOptions();
|
||||
}
|
||||
}));
|
||||
|
@ -93,7 +93,9 @@ export class CellEditorOptions extends Disposable {
|
|||
const renderLiNumbers = this.configurationService.getValue<'on' | 'off'>('notebook.lineNumbers') === 'on';
|
||||
const lineNumbers: LineNumbersType = renderLiNumbers ? 'on' : 'off';
|
||||
const editorOptions = deepClone(this.configurationService.getValue<IEditorOptions>('editor', { overrideIdentifier: this.language }));
|
||||
const editorOptionsOverrideRaw = this.notebookOptions.getLayoutConfiguration().editorOptionsCustomizations ?? {};
|
||||
const layoutConfig = this.notebookOptions.getLayoutConfiguration();
|
||||
const cellBreakpointMargin = layoutConfig.cellBreakpointMarginActive;
|
||||
const editorOptionsOverrideRaw = layoutConfig.editorOptionsCustomizations ?? {};
|
||||
let editorOptionsOverride: { [key: string]: any; } = {};
|
||||
for (let key in editorOptionsOverrideRaw) {
|
||||
if (key.indexOf('editor.') === 0) {
|
||||
|
@ -106,7 +108,8 @@ export class CellEditorOptions extends Disposable {
|
|||
... { lineNumbers },
|
||||
...editorOptionsOverride,
|
||||
...{ padding: { top: 12, bottom: 12 } },
|
||||
readonly: this.notebookEditor.viewModel?.options.isReadOnly ?? false
|
||||
readonly: this.notebookEditor.viewModel?.options.isReadOnly ?? false,
|
||||
glyphMargin: cellBreakpointMargin
|
||||
};
|
||||
|
||||
if (!computed.folding) {
|
||||
|
@ -132,13 +135,6 @@ export class CellEditorOptions extends Disposable {
|
|||
};
|
||||
}
|
||||
|
||||
setGlyphMargin(gm: boolean): void {
|
||||
if (gm !== this._value.glyphMargin) {
|
||||
this._value.glyphMargin = gm;
|
||||
this._onDidChange.fire();
|
||||
}
|
||||
}
|
||||
|
||||
setLineNumbers(lineNumbers: 'on' | 'off' | 'inherit'): void {
|
||||
this._lineNumbers = lineNumbers;
|
||||
if (this._lineNumbers === 'inherit') {
|
||||
|
@ -256,3 +252,37 @@ registerAction2(class ToggleActiveLineNumberAction extends Action2 {
|
|||
}
|
||||
}
|
||||
});
|
||||
|
||||
registerAction2(class ToggleCellBreakpointMargin extends NotebookAction {
|
||||
constructor() {
|
||||
super({
|
||||
id: 'notebook.toggleBreakpointMargin',
|
||||
title: localize('notebookActions.toggleBreakpointMargin', "Toggle Cell Breakpoint Margin"),
|
||||
menu: [{
|
||||
id: MenuId.EditorTitle,
|
||||
group: 'notebookLayout',
|
||||
order: 3,
|
||||
when: ContextKeyExpr.and(
|
||||
NOTEBOOK_IS_ACTIVE_EDITOR,
|
||||
ContextKeyExpr.notEquals('config.notebook.globalToolbar', true)
|
||||
)
|
||||
}, {
|
||||
id: MenuId.NotebookToolbar,
|
||||
group: 'notebookLayout',
|
||||
order: 3,
|
||||
when: ContextKeyExpr.equals('config.notebook.globalToolbar', true)
|
||||
}],
|
||||
category: NOTEBOOK_ACTIONS_CATEGORY,
|
||||
f1: true,
|
||||
toggled: {
|
||||
condition: NOTEBOOK_BREAKPOINT_MARGIN_ACTIVE,
|
||||
title: { value: localize('notebook.showBreakpointMargin', "Show Breakpoints"), original: 'Show Breakpoints' },
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async runWithContext(accessor: ServicesAccessor, context: INotebookActionContext): Promise<void> {
|
||||
const opts = context.notebookEditor.notebookOptions;
|
||||
opts.setCellBreakpointMarginActive(!opts.getLayoutConfiguration().cellBreakpointMarginActive);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -59,6 +59,7 @@ export interface NotebookLayoutConfiguration {
|
|||
fontSize: number;
|
||||
focusIndicatorLeftMargin: number;
|
||||
editorOptionsCustomizations: any | undefined;
|
||||
cellBreakpointMarginActive: boolean;
|
||||
}
|
||||
|
||||
interface NotebookOptionsChangeEvent {
|
||||
|
@ -77,6 +78,7 @@ interface NotebookOptionsChangeEvent {
|
|||
dragAndDropEnabled?: boolean;
|
||||
fontSize?: boolean;
|
||||
editorOptionsCustomizations?: boolean;
|
||||
cellBreakpointMargin?: boolean;
|
||||
}
|
||||
|
||||
const defaultConfigConstants = {
|
||||
|
@ -151,7 +153,8 @@ export class NotebookOptions {
|
|||
insertToolbarAlignment,
|
||||
showFoldingControls,
|
||||
fontSize,
|
||||
editorOptionsCustomizations
|
||||
editorOptionsCustomizations,
|
||||
cellBreakpointMarginActive: false
|
||||
};
|
||||
|
||||
this._disposables.push(this.configurationService.onDidChangeConfiguration(e => {
|
||||
|
@ -481,6 +484,11 @@ export class NotebookOptions {
|
|||
};
|
||||
}
|
||||
|
||||
setCellBreakpointMarginActive(active: boolean) {
|
||||
this._layoutConfiguration.cellBreakpointMarginActive = active;
|
||||
this._onDidChangeOptions.fire({ cellBreakpointMargin: true });
|
||||
}
|
||||
|
||||
dispose() {
|
||||
this._disposables.forEach(d => d.dispose());
|
||||
this._disposables = [];
|
||||
|
|
Loading…
Reference in a new issue