mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-16 09:35:36 -05:00
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:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user