Merge pull request #131147 from microsoft/dev/joyceerhl/notebook-toggle-output
Implement `notebook.cell.toggleOutputs` to toggle output visibility of notebook cells
This commit is contained in:
commit
2decbaa5b5
1 changed files with 41 additions and 0 deletions
|
@ -71,6 +71,7 @@ const EXECUTE_CELL_INSERT_BELOW = 'notebook.cell.executeAndInsertBelow';
|
||||||
const EXECUTE_CELL_AND_BELOW = 'notebook.cell.executeCellAndBelow';
|
const EXECUTE_CELL_AND_BELOW = 'notebook.cell.executeCellAndBelow';
|
||||||
const EXECUTE_CELLS_ABOVE = 'notebook.cell.executeCellsAbove';
|
const EXECUTE_CELLS_ABOVE = 'notebook.cell.executeCellsAbove';
|
||||||
const CLEAR_CELL_OUTPUTS_COMMAND_ID = 'notebook.cell.clearOutputs';
|
const CLEAR_CELL_OUTPUTS_COMMAND_ID = 'notebook.cell.clearOutputs';
|
||||||
|
const TOGGLE_CELL_OUTPUTS_COMMAND_ID = 'notebook.cell.toggleOutputs';
|
||||||
const CENTER_ACTIVE_CELL = 'notebook.centerActiveCell';
|
const CENTER_ACTIVE_CELL = 'notebook.centerActiveCell';
|
||||||
|
|
||||||
const COLLAPSE_CELL_INPUT_COMMAND_ID = 'notebook.cell.collapseCellInput';
|
const COLLAPSE_CELL_INPUT_COMMAND_ID = 'notebook.cell.collapseCellInput';
|
||||||
|
@ -691,6 +692,46 @@ registerAction2(class CancelExecuteCell extends NotebookMultiCellAction<INoteboo
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
registerAction2(class extends NotebookMultiCellAction<INotebookActionContext> {
|
||||||
|
constructor() {
|
||||||
|
super({
|
||||||
|
id: TOGGLE_CELL_OUTPUTS_COMMAND_ID,
|
||||||
|
precondition: NOTEBOOK_CELL_LIST_FOCUSED,
|
||||||
|
title: localize('notebookActions.toggleOutputs', "Toggle Outputs"),
|
||||||
|
description: {
|
||||||
|
description: localize('notebookActions.toggleOutputs', "Toggle Outputs"),
|
||||||
|
args: cellExecutionArgs
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
parseArgs(accessor: ServicesAccessor, ...args: any[]): INotebookActionContext | undefined {
|
||||||
|
return parseMultiCellExecutionArgs(accessor, ...args);
|
||||||
|
}
|
||||||
|
|
||||||
|
async runWithContext(accessor: ServicesAccessor, context: INotebookActionContext): Promise<void> {
|
||||||
|
const textModel = context.notebookEditor.viewModel.notebookDocument;
|
||||||
|
let cells: ICellViewModel[] = [];
|
||||||
|
if (context.ui && context.cell) {
|
||||||
|
cells = [context.cell];
|
||||||
|
} else if (context.selectedCells) {
|
||||||
|
cells = [...context.selectedCells];
|
||||||
|
} else {
|
||||||
|
cells = [...context.notebookEditor.viewModel.getCells()];
|
||||||
|
}
|
||||||
|
|
||||||
|
const edits: ICellEditOperation[] = [];
|
||||||
|
for (const cell of cells) {
|
||||||
|
const index = textModel.cells.indexOf(cell.model);
|
||||||
|
if (index >= 0) {
|
||||||
|
edits.push({ editType: CellEditType.Metadata, index, metadata: { ...cell.metadata, outputCollapsed: !cell.metadata.outputCollapsed } });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
textModel.applyEdits(edits, true, undefined, () => undefined, undefined);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
export class DeleteCellAction extends MenuItemAction {
|
export class DeleteCellAction extends MenuItemAction {
|
||||||
constructor(
|
constructor(
|
||||||
@IContextKeyService contextKeyService: IContextKeyService,
|
@IContextKeyService contextKeyService: IContextKeyService,
|
||||||
|
|
Loading…
Reference in a new issue