Skip to content

Commit cff5a8d

Browse files
Copilotamunger
andauthored
Add "Stop Editing All Cells" command for notebooks (microsoft#259585)
* Initial plan * Add Stop Editing All Cells command implementation Co-authored-by: amunger <[email protected]> * set focus on cell container --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: amunger <[email protected]>
1 parent e04f2f9 commit cff5a8d

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import { NotebookInlineVariablesController } from '../contrib/notebookVariables/
4545
const CLEAR_ALL_CELLS_OUTPUTS_COMMAND_ID = 'notebook.clearAllCellsOutputs';
4646
const EDIT_CELL_COMMAND_ID = 'notebook.cell.edit';
4747
const DELETE_CELL_COMMAND_ID = 'notebook.cell.delete';
48+
const QUIT_EDIT_ALL_CELLS_COMMAND_ID = 'notebook.quitEditAllCells';
4849
export const CLEAR_CELL_OUTPUTS_COMMAND_ID = 'notebook.cell.clearOutputs';
4950
export const SELECT_NOTEBOOK_INDENTATION_ID = 'notebook.selectIndentation';
5051
export const COMMENT_SELECTED_CELLS_ID = 'notebook.commentSelectedCells';
@@ -151,6 +152,41 @@ registerAction2(class QuitEditCellAction extends NotebookCellAction {
151152
}
152153
});
153154

155+
registerAction2(class QuitEditAllCellsAction extends NotebookAction {
156+
constructor() {
157+
super(
158+
{
159+
id: QUIT_EDIT_ALL_CELLS_COMMAND_ID,
160+
title: localize('notebookActions.quitEditAllCells', "Stop Editing All Cells")
161+
});
162+
}
163+
164+
async runWithContext(accessor: ServicesAccessor, context: INotebookActionContext) {
165+
if (!context.notebookEditor.hasModel()) {
166+
return;
167+
}
168+
169+
const viewModel = context.notebookEditor.getViewModel();
170+
if (!viewModel) {
171+
return;
172+
}
173+
174+
const activeCell = context.notebookEditor.getActiveCell();
175+
176+
const editingCells = viewModel.viewCells.filter(cell =>
177+
cell.cellKind === CellKind.Markup && cell.getEditState() === CellEditState.Editing
178+
);
179+
180+
editingCells.forEach(cell => {
181+
cell.updateEditState(CellEditState.Preview, QUIT_EDIT_ALL_CELLS_COMMAND_ID);
182+
});
183+
184+
if (activeCell) {
185+
await context.notebookEditor.focusNotebookCell(activeCell, 'container', { skipReveal: true });
186+
}
187+
}
188+
});
189+
154190
registerAction2(class DeleteCellAction extends NotebookCellAction {
155191
constructor() {
156192
super(

0 commit comments

Comments
 (0)