Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Meaningful timeline entries for notebooks #207531

Merged
merged 3 commits into from
Mar 13, 2024
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
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
Loading