diff --git a/src/vs/vscode.proposed.d.ts b/src/vs/vscode.proposed.d.ts index 12d667c74cf..f033c7635f8 100644 --- a/src/vs/vscode.proposed.d.ts +++ b/src/vs/vscode.proposed.d.ts @@ -1110,7 +1110,7 @@ declare module 'vscode' { * * The primary selection (or focused range) is `selections[0]`. When the document has no cells, the primary selection is empty `{ start: 0, end: 0 }`; */ - readonly selections: NotebookRange[]; + selections: NotebookRange[]; /** * The current visible ranges in the editor (vertically). diff --git a/src/vs/workbench/api/browser/mainThreadNotebookEditors.ts b/src/vs/workbench/api/browser/mainThreadNotebookEditors.ts index 9777a4bae95..76c0c0a4000 100644 --- a/src/vs/workbench/api/browser/mainThreadNotebookEditors.ts +++ b/src/vs/workbench/api/browser/mainThreadNotebookEditors.ts @@ -186,4 +186,12 @@ export class MainThreadNotebookEditors implements MainThreadNotebookEditorsShape notebookEditor.setEditorDecorations(key, range); } } + + $trySetSelections(id: string, ranges: ICellRange[]): void { + const editor = this._notebookEditorService.getNotebookEditor(id); + if (editor) { + // @rebornix how to set an editor selection? + // editor.setSelections(ranges) + } + } } diff --git a/src/vs/workbench/api/common/extHost.protocol.ts b/src/vs/workbench/api/common/extHost.protocol.ts index 550c3547cd0..07850c4c4f6 100644 --- a/src/vs/workbench/api/common/extHost.protocol.ts +++ b/src/vs/workbench/api/common/extHost.protocol.ts @@ -894,6 +894,7 @@ export interface MainThreadNotebookEditorsShape extends IDisposable { $tryRevealRange(id: string, range: ICellRange, revealType: NotebookEditorRevealType): Promise; $registerNotebookEditorDecorationType(key: string, options: INotebookDecorationRenderOptions): void; $removeNotebookEditorDecorationType(key: string): void; + $trySetSelections(id: string, range: ICellRange[]): void; $trySetDecorations(id: string, range: ICellRange, decorationKey: string): void; $tryApplyEdits(editorId: string, modelVersionId: number, cellEdits: ICellEditOperation[]): Promise } diff --git a/src/vs/workbench/api/common/extHostNotebookEditor.ts b/src/vs/workbench/api/common/extHostNotebookEditor.ts index a3b7fabf34f..479d1469902 100644 --- a/src/vs/workbench/api/common/extHostNotebookEditor.ts +++ b/src/vs/workbench/api/common/extHostNotebookEditor.ts @@ -9,6 +9,7 @@ import * as extHostConverter from 'vs/workbench/api/common/extHostTypeConverters import { CellEditType, ICellEditOperation, ICellReplaceEdit } from 'vs/workbench/contrib/notebook/common/notebookCommon'; import * as vscode from 'vscode'; import { ExtHostNotebookDocument } from './extHostNotebookDocument'; +import { illegalArgument } from 'vs/base/common/errors'; interface INotebookEditData { documentVersionId: number; @@ -107,6 +108,13 @@ export class ExtHostNotebookEditor { get selections() { return that._selections; }, + set selections(value: vscode.NotebookRange[]) { + if (!Array.isArray(value) || !value.every(extHostTypes.NotebookRange.isNotebookRange)) { + throw illegalArgument('selections'); + } + that._selections = value; + that._trySetSelections(value); + }, get visibleRanges() { return that._visibleRanges; }, @@ -151,6 +159,10 @@ export class ExtHostNotebookEditor { this._selections = selections; } + private _trySetSelections(value: vscode.NotebookRange[]): void { + this._proxy.$trySetSelections(this.id, value.map(extHostConverter.NotebookRange.from)); + } + _acceptViewColumn(value: vscode.ViewColumn | undefined) { this._viewColumn = value; }