From 31e507e8c7d160233f89463656c8aadc7b9e0ae8 Mon Sep 17 00:00:00 2001 From: Jonah Iden Date: Thu, 29 Aug 2024 08:47:30 +0200 Subject: [PATCH 1/2] fixed initial selection Signed-off-by: Jonah Iden --- .../browser/notebooks/notebook-editors-main.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/plugin-ext/src/main/browser/notebooks/notebook-editors-main.ts b/packages/plugin-ext/src/main/browser/notebooks/notebook-editors-main.ts index 1a479206da286..27f15e8d45aad 100644 --- a/packages/plugin-ext/src/main/browser/notebooks/notebook-editors-main.ts +++ b/packages/plugin-ext/src/main/browser/notebooks/notebook-editors-main.ts @@ -54,12 +54,25 @@ export class NotebookEditorsMainImpl implements NotebookEditorsMain { throw new Error('Method not implemented.'); } $trySetSelections(id: string, range: CellRange[]): void { - throw new Error('Method not implemented.'); + if (!this.mainThreadEditors.has(id)) { + throw new Error('Editor not found'); + } + const editor = this.mainThreadEditors.get(id); + editor?.model?.setSelectedCell(editor.model.cells[range[0].start]); } - handleEditorsAdded(editors: readonly NotebookEditorWidget[]): void { + async handleEditorsAdded(editors: readonly NotebookEditorWidget[]): Promise { for (const editor of editors) { this.mainThreadEditors.set(editor.id, editor); + const model = await editor.ready; + model.onDidChangeSelectedCell(e => { + const newCellIndex = e.cell ? model.cells.indexOf(e.cell) : -1; + this.proxy.$acceptEditorPropertiesChanged(editor.id, { + selections: { + selections: newCellIndex >= 0 ? [{ start: newCellIndex, end: newCellIndex }] : [] + } + }); + }); } } From ab6a7ae5e375972efdb8bce0e2050a06d724ed8f Mon Sep 17 00:00:00 2001 From: Jonah Iden Date: Thu, 29 Aug 2024 09:08:55 +0200 Subject: [PATCH 2/2] fixed initial selection Signed-off-by: Jonah Iden --- .../browser/notebooks/notebook-documents-and-editors-main.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/plugin-ext/src/main/browser/notebooks/notebook-documents-and-editors-main.ts b/packages/plugin-ext/src/main/browser/notebooks/notebook-documents-and-editors-main.ts index b41159f8e2f0f..46c73e5a2fec4 100644 --- a/packages/plugin-ext/src/main/browser/notebooks/notebook-documents-and-editors-main.ts +++ b/packages/plugin-ext/src/main/browser/notebooks/notebook-documents-and-editors-main.ts @@ -242,7 +242,7 @@ export class NotebooksAndEditorsMain implements NotebookDocumentsAndEditorsMain return { id: notebookEditor.id, documentUri: uri.toComponents(), - selections: [], + selections: [{ start: 0, end: 0 }], visibleRanges: [] }; }