Skip to content

Commit 9038464

Browse files
committed
more cases for restricting undo/redo
1 parent d4094a4 commit 9038464

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,8 @@ registerAction2(class ClearCellOutputsAction extends NotebookCellAction {
201201
return;
202202
}
203203

204-
editor.textModel.applyEdits([{ editType: CellEditType.Output, index, outputs: [] }], true, undefined, () => undefined, undefined, true);
204+
const computeUndoRedo = !editor.isReadOnly;
205+
editor.textModel.applyEdits([{ editType: CellEditType.Output, index, outputs: [] }], true, undefined, () => undefined, undefined, computeUndoRedo);
205206

206207
const runState = notebookExecutionStateService.getCellExecution(context.cell.uri)?.state;
207208
if (runState !== NotebookCellExecutionState.Executing) {
@@ -213,7 +214,7 @@ registerAction2(class ClearCellOutputsAction extends NotebookCellAction {
213214
executionOrder: null,
214215
lastRunSuccess: null
215216
}
216-
}], true, undefined, () => undefined, undefined, true);
217+
}], true, undefined, () => undefined, undefined, computeUndoRedo);
217218
}
218219
}
219220
});
@@ -256,10 +257,11 @@ registerAction2(class ClearAllCellOutputsAction extends NotebookAction {
256257
return;
257258
}
258259

260+
const computeUndoRedo = !editor.isReadOnly;
259261
editor.textModel.applyEdits(
260262
editor.textModel.cells.map((cell, index) => ({
261263
editType: CellEditType.Output, index, outputs: []
262-
})), true, undefined, () => undefined, undefined, true);
264+
})), true, undefined, () => undefined, undefined, computeUndoRedo);
263265

264266
const clearExecutionMetadataEdits = editor.textModel.cells.map((cell, index) => {
265267
const runState = notebookExecutionStateService.getCellExecution(cell.uri)?.state;
@@ -278,7 +280,7 @@ registerAction2(class ClearAllCellOutputsAction extends NotebookAction {
278280
}
279281
}).filter(edit => !!edit) as ICellEditOperation[];
280282
if (clearExecutionMetadataEdits.length) {
281-
context.notebookEditor.textModel.applyEdits(clearExecutionMetadataEdits, true, undefined, () => undefined, undefined, true);
283+
context.notebookEditor.textModel.applyEdits(clearExecutionMetadataEdits, true, undefined, () => undefined, undefined, computeUndoRedo);
282284
}
283285
}
284286
});
@@ -498,7 +500,7 @@ async function setCellToLanguage(languageId: string, context: IChangeCellContext
498500
const index = context.notebookEditor.textModel.cells.indexOf(context.cell.model);
499501
context.notebookEditor.textModel.applyEdits(
500502
[{ editType: CellEditType.CellLanguage, index, language: languageId }],
501-
true, undefined, () => undefined, undefined, true
503+
true, undefined, () => undefined, undefined, !context.notebookEditor.isReadOnly
502504
);
503505
}
504506
}

0 commit comments

Comments
 (0)