Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix vscode api notebook selection property #14087

Merged
merged 2 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ export class NotebooksAndEditorsMain implements NotebookDocumentsAndEditorsMain
return {
id: notebookEditor.id,
documentUri: uri.toComponents(),
selections: [],
selections: [{ start: 0, end: 0 }],
visibleRanges: []
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
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 }] : []
}
});
});
}
}

Expand Down
Loading