Skip to content

Commit

Permalink
NotebookEditorEdit-api changes, #105283
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Sep 14, 2020
1 parent ef4df1d commit 06377cf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 42 deletions.
23 changes: 11 additions & 12 deletions src/vs/vscode.proposed.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1405,21 +1405,10 @@ declare module 'vscode' {
}

export interface NotebookEditorEdit {

replaceNotebookMetadata(value: NotebookDocumentMetadata): void;

replaceMetadata(value: NotebookDocumentMetadata): void;
replaceCells(start: number, end: number, cells: NotebookCellData[]): void;
replaceCellOutput(index: number, outputs: CellOutput[]): void;
replaceCellMetadata(index: number, metadata: NotebookCellMetadata): void;

/** @deprecated */
replaceOutput(index: number, outputs: CellOutput[]): void;
/** @deprecated */
replaceMetadata(index: number, metadata: NotebookCellMetadata): void;
/** @deprecated */
insert(index: number, content: string | string[], language: string, type: CellKind, outputs: CellOutput[], metadata: NotebookCellMetadata | undefined): void;
/** @deprecated */
delete(index: number): void;
}

export interface NotebookCellRange {
Expand Down Expand Up @@ -1503,6 +1492,16 @@ declare module 'vscode' {
*/
asWebviewUri(localResource: Uri): Uri;

/**
* Perform an edit on the notebook associated with this notebook editor.
*
* The given callback-function is invoked with an [edit-builder](#NotebookEditorEdit) which must
* be used to make edits. Note that the edit-builder is only valid while the
* callback executes.
*
* @param callback A function which can create edits using an [edit-builder](#NotebookEditorEdit).
* @return A promise that resolves with a value indicating if the edits could be applied.
*/
edit(callback: (editBuilder: NotebookEditorEdit) => void): Thenable<boolean>;

revealRange(range: NotebookCellRange, revealType?: NotebookEditorRevealType): void;
Expand Down
32 changes: 2 additions & 30 deletions src/vs/workbench/api/common/extHostNotebookEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { readonly } from 'vs/base/common/errors';
import { Emitter, Event } from 'vs/base/common/event';
import { Disposable } from 'vs/base/common/lifecycle';
import { CellKind, MainThreadNotebookShape } from 'vs/workbench/api/common/extHost.protocol';
import { MainThreadNotebookShape } from 'vs/workbench/api/common/extHost.protocol';
import * as extHostTypes from 'vs/workbench/api/common/extHostTypes';
import { addIdToOutput, CellEditType, ICellEditOperation, ICellReplaceEdit, INotebookEditData, notebookDocumentMetadataDefaults } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import * as vscode from 'vscode';
Expand Down Expand Up @@ -37,7 +37,7 @@ class NotebookEditorCellEditBuilder implements vscode.NotebookEditorEdit {
}
}

replaceNotebookMetadata(value: vscode.NotebookDocumentMetadata): void {
replaceMetadata(value: vscode.NotebookDocumentMetadata): void {
this._throwIfFinalized();
this._collectedEdits.push({
editType: CellEditType.DocumentMetadata,
Expand All @@ -54,12 +54,6 @@ class NotebookEditorCellEditBuilder implements vscode.NotebookEditorEdit {
});
}

replaceMetadata(index: number, metadata: vscode.NotebookCellMetadata): void {
console.warn('DEPRECATED use "replaceCellMetadata" instead');
this.replaceCellMetadata(index, metadata);
}


replaceCellOutput(index: number, outputs: vscode.CellOutput[]): void {
this._throwIfFinalized();
this._collectedEdits.push({
Expand All @@ -69,14 +63,8 @@ class NotebookEditorCellEditBuilder implements vscode.NotebookEditorEdit {
});
}

replaceOutput(index: number, outputs: vscode.CellOutput[]): void {
console.warn('DEPRECATED use "replaceCellOutput" instead');
this.replaceCellOutput(index, outputs);
}

replaceCells(from: number, to: number, cells: vscode.NotebookCellData[]): void {
this._throwIfFinalized();

this._collectedEdits.push({
editType: CellEditType.Replace,
index: from,
Expand All @@ -89,22 +77,6 @@ class NotebookEditorCellEditBuilder implements vscode.NotebookEditorEdit {
})
});
}

insert(index: number, content: string | string[], language: string, type: CellKind, outputs: vscode.CellOutput[], metadata: vscode.NotebookCellMetadata | undefined): void {
this._throwIfFinalized();
this.replaceCells(index, index, [{
language,
outputs,
metadata,
cellKind: type,
source: Array.isArray(content) ? content.join('\n') : content,
}]);
}

delete(index: number): void {
this._throwIfFinalized();
this.replaceCells(index, 1, []);
}
}

export class ExtHostNotebookEditor extends Disposable implements vscode.NotebookEditor {
Expand Down

0 comments on commit 06377cf

Please sign in to comment.