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:
Peng Lyu 2021-08-19 09:15:07 -07:00 committed by GitHub
commit 2decbaa5b5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -71,6 +71,7 @@ const EXECUTE_CELL_INSERT_BELOW = 'notebook.cell.executeAndInsertBelow';
const EXECUTE_CELL_AND_BELOW = 'notebook.cell.executeCellAndBelow';
const EXECUTE_CELLS_ABOVE = 'notebook.cell.executeCellsAbove';
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 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 {
constructor(
@IContextKeyService contextKeyService: IContextKeyService,