cellCount and cellAt API proposal so that notebook aligns better with text document

上级 bbdc0e4c
......@@ -1066,11 +1066,23 @@ declare module 'vscode' {
// todo@API should we really expose this?
readonly viewType: string;
// todo@API add cellAt(index): NotebookCell
// todo@API add cellCount: number;
// todo@API cellsAt(range)? getCell(index>)?
/** @deprecated Use `getCells(<...>) instead */
readonly cells: ReadonlyArray<NotebookCell>;
/**
* The number of cells in the notebook document.
*/
readonly cellCount: number;
/**
* Return the cell at the specified index. The index will be adjusted to the notebook.
*
* @param index - The index of the cell to retrieve.
* @return A [cell](#NotebookCell).
*/
cellAt(index: number): NotebookCell;
/**
* Get the cells of this notebook. A subset can be retrieved by providing
* a range. The range will be adjuset to the notebook.
......
......@@ -179,8 +179,12 @@ export class ExtHostNotebookDocument extends Disposable {
get isUntitled() { return that.uri.scheme === Schemas.untitled; },
get isClosed() { return that._disposed; },
get metadata() { return that._metadata; },
set metadata(_value: Required<vscode.NotebookDocumentMetadata>) { throw new Error('Use WorkspaceEdit to update metadata.'); },
get cells(): ReadonlyArray<vscode.NotebookCell> { return that._cells.map(cell => cell.cell); },
get cellCount() { return that._cells.length; },
cellAt(index) {
index = that._validateIndex(index);
return that._cells[index].cell;
},
getCells(range) {
const cells = range ? that._getCells(range) : that._cells;
return cells.map(cell => cell.cell);
......@@ -232,6 +236,16 @@ export class ExtHostNotebookDocument extends Disposable {
}
}
private _validateIndex(index: number): number {
if (index < 0) {
return 0;
} else if (index >= this._cells.length) {
return this._cells.length - 1;
} else {
return index;
}
}
private _validateRange(range: vscode.NotebookCellRange): vscode.NotebookCellRange {
if (range.start < 0) {
range = range.with({ start: 0 });
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册