Notebooks: Add Command + Keyboard Shortcut to Clear Outputs of Active Cell (#6169)

* Add command to clear cell output with test

* Fix typo

* PR Comments
This commit is contained in:
Chris LaFreniere
2019-06-26 15:19:12 -07:00
committed by GitHub
parent caba5c9d26
commit 77fb060fde
10 changed files with 110 additions and 3 deletions

View File

@@ -159,6 +159,11 @@ export class ExtHostNotebookEditor implements azdata.nb.NotebookEditor, IDisposa
return this._proxy.$runAllCells(this._id);
}
public clearOutput(cell: azdata.nb.NotebookCell): Thenable<boolean> {
let uri = cell ? cell.uri : undefined;
return this._proxy.$clearOutput(this._id, uri);
}
public clearAllOutputs(): Thenable<boolean> {
return this._proxy.$clearAllOutputs(this._id);
}

View File

@@ -139,6 +139,13 @@ class MainThreadNotebookEditor extends Disposable {
return this.editor.runAllCells();
}
public clearOutput(cell: ICellModel): Promise<boolean> {
if (!this.editor) {
return Promise.resolve(false);
}
return this.editor.clearOutput(cell);
}
public clearAllOutputs(): Promise<boolean> {
if (!this.editor) {
return Promise.resolve(false);
@@ -384,6 +391,28 @@ export class MainThreadNotebookDocumentsAndEditors extends Disposable implements
return editor.runAllCells();
}
$clearOutput(id: string, cellUri: UriComponents): Promise<boolean> {
// Requires an editor and the matching cell in that editor
let editor = this.getEditor(id);
if (!editor) {
return Promise.reject(disposed(`TextEditor(${id})`));
}
let cell: ICellModel;
if (cellUri) {
let uriString = URI.revive(cellUri).toString();
cell = editor.cells.find(c => c.cellUri.toString() === uriString);
// If it's markdown what should we do? Show notification??
} else {
// Use the active cell in this case, or 1st cell if there's none active
cell = editor.model.activeCell;
}
if (!cell || (cell && cell.cellType !== CellTypes.Code)) {
return Promise.reject(localize('clearResultActiveCell', "Clear result requires a code cell to be selected. Please select a code cell to run."));
}
return editor.clearOutput(cell);
}
$clearAllOutputs(id: string): Promise<boolean> {
let editor = this.getEditor(id);
if (!editor) {

View File

@@ -920,6 +920,7 @@ export interface MainThreadNotebookDocumentsAndEditorsShape extends IDisposable
$tryApplyEdits(id: string, modelVersionId: number, edits: ISingleNotebookEditOperation[], opts: IUndoStopOptions): Promise<boolean>;
$runCell(id: string, cellUri: UriComponents): Promise<boolean>;
$runAllCells(id: string): Promise<boolean>;
$clearOutput(id: string, cellUri: UriComponents): Promise<boolean>;
$clearAllOutputs(id: string): Promise<boolean>;
$changeKernel(id: string, kernel: azdata.nb.IKernelInfo): Promise<boolean>;
}