Skip to content

Commit d4094a4

Browse files
committed
don't allow undo for read-only notebooks
1 parent 833cbca commit d4094a4

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/vs/workbench/contrib/notebook/browser/controller/cellOperations.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ export function runDeleteAction(editor: IActiveNotebookEditor, cell: ICellViewMo
123123
const targetCellIndex = editor.getCellIndex(cell);
124124
const containingSelection = selections.find(selection => selection.start <= targetCellIndex && targetCellIndex < selection.end);
125125

126+
const computeUndoRedo = !editor.isReadOnly || textModel.viewType === 'interactive';
126127
if (containingSelection) {
127128
const edits: ICellReplaceEdit[] = selections.reverse().map(selection => ({
128129
editType: CellEditType.Replace, index: selection.start, count: selection.end - selection.start, cells: []
@@ -143,7 +144,7 @@ export function runDeleteAction(editor: IActiveNotebookEditor, cell: ICellViewMo
143144
return { kind: SelectionStateType.Index, focus: { start: 0, end: 0 }, selections: [{ start: 0, end: 0 }] };
144145
}
145146
}
146-
}, undefined, true);
147+
}, undefined, computeUndoRedo);
147148
} else {
148149
const focus = editor.getFocus();
149150
const edits: ICellReplaceEdit[] = [{
@@ -169,14 +170,14 @@ export function runDeleteAction(editor: IActiveNotebookEditor, cell: ICellViewMo
169170

170171
textModel.applyEdits(edits, true, { kind: SelectionStateType.Index, focus: editor.getFocus(), selections: editor.getSelections() }, () => ({
171172
kind: SelectionStateType.Index, focus: newFocus, selections: finalSelections
172-
}), undefined, true);
173+
}), undefined, computeUndoRedo);
173174
} else {
174175
// users decide to delete a cell out of current focus/selection
175176
const newFocus = focus.start > targetCellIndex ? { start: focus.start - 1, end: focus.end - 1 } : focus;
176177

177178
textModel.applyEdits(edits, true, { kind: SelectionStateType.Index, focus: editor.getFocus(), selections: editor.getSelections() }, () => ({
178179
kind: SelectionStateType.Index, focus: newFocus, selections: finalSelections
179-
}), undefined, true);
180+
}), undefined, computeUndoRedo);
180181
}
181182
}
182183
}

0 commit comments

Comments
 (0)