Skip to content

Commit

Permalink
Meaningful timeline entries for notebooks (#207531)
Browse files Browse the repository at this point in the history
* pushStackElement API in NB Model to be same as same API in Text Model

* More meaningful timeline entries for Notebooks
  • Loading branch information
DonJayamanne authored Mar 13, 2024
1 parent 0e6e4b6 commit 215064c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
16 changes: 14 additions & 2 deletions src/vs/workbench/contrib/notebook/common/model/cellEdit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<NotebookTextModelChangedEvent>,
private _postUndoRedo: (alternativeVersionId: string) => void,
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 215064c

Please sign in to comment.