diff --git a/src/vs/workbench/contrib/notebook/common/model/cellEdit.ts b/src/vs/workbench/contrib/notebook/common/model/cellEdit.ts index 3291110ac933b..22e305c98ad6a 100644 --- a/src/vs/workbench/contrib/notebook/common/model/cellEdit.ts +++ b/src/vs/workbench/contrib/notebook/common/model/cellEdit.ts @@ -21,7 +21,9 @@ export interface ITextCellEditingDelegate { export class MoveCellEdit implements IResourceUndoRedoElement { type: UndoRedoElementType.Resource = UndoRedoElementType.Resource; - label: string = 'Move Cell'; + get label() { + return this.length === 1 ? 'Move Cell' : 'Move Cells'; + } code: string = 'undoredo.notebooks.moveCell'; constructor( @@ -54,7 +56,17 @@ export class MoveCellEdit implements IResourceUndoRedoElement { export class SpliceCellsEdit implements IResourceUndoRedoElement { type: UndoRedoElementType.Resource = UndoRedoElementType.Resource; - label: string = 'Insert Cell'; + get label() { + // Compute the most appropriate labels + if (this.diffs.length === 1 && this.diffs[0][1].length === 0) { + return this.diffs[0][2].length > 1 ? 'Insert Cells' : 'Insert Cell'; + } + if (this.diffs.length === 1 && this.diffs[0][2].length === 0) { + return this.diffs[0][1].length > 1 ? 'Delete Cells' : 'Delete Cell'; + } + // Default to Insert Cell + return 'Insert Cell'; + } code: string = 'undoredo.notebooks.insertCell'; constructor( public resource: URI, diff --git a/src/vs/workbench/contrib/notebook/common/model/notebookTextModel.ts b/src/vs/workbench/contrib/notebook/common/model/notebookTextModel.ts index 6e3de870d47c5..179e7fbc458fe 100644 --- a/src/vs/workbench/contrib/notebook/common/model/notebookTextModel.ts +++ b/src/vs/workbench/contrib/notebook/common/model/notebookTextModel.ts @@ -32,10 +32,12 @@ class StackOperation implements IWorkspaceUndoRedoElement { private _resultSelectionState: ISelectionState | undefined = undefined; private _beginAlternativeVersionId: string; private _resultAlternativeVersionId: string; + public get label() { + return this._operations.length === 1 ? this._operations[0].label : 'edit'; + } constructor( readonly textModel: NotebookTextModel, - readonly label: string, readonly undoRedoGroup: UndoRedoGroup | undefined, private _pauseableEmitter: PauseableEmitter, private _postUndoRedo: (alternativeVersionId: string) => void, @@ -124,7 +126,7 @@ class NotebookOperationManager { this._pendingStackOperation = null; } private _getOrCreateEditStackElement(beginSelectionState: ISelectionState | undefined, undoRedoGroup: UndoRedoGroup | undefined, alternativeVersionId: string) { - return this._pendingStackOperation ??= new StackOperation(this._textModel, 'edit', undoRedoGroup, this._pauseableEmitter, this._postUndoRedo, beginSelectionState, alternativeVersionId || ''); + return this._pendingStackOperation ??= new StackOperation(this._textModel, undoRedoGroup, this._pauseableEmitter, this._postUndoRedo, beginSelectionState, alternativeVersionId || ''); } pushEditOperation(element: IUndoRedoElement, beginSelectionState: ISelectionState | undefined, resultSelectionState: ISelectionState | undefined, alternativeVersionId: string, undoRedoGroup: UndoRedoGroup | undefined) {