From 54bd1b106cfb5298ebf9fe08f6c04e772fa0da01 Mon Sep 17 00:00:00 2001 From: Nick Strayer Date: Wed, 15 Oct 2025 12:09:22 -0400 Subject: [PATCH 1/7] Fix empty editor bug --- .../browser/PositronNotebookEditor.tsx | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/vs/workbench/contrib/positronNotebook/browser/PositronNotebookEditor.tsx b/src/vs/workbench/contrib/positronNotebook/browser/PositronNotebookEditor.tsx index 629b1c8c0e7e..f69f53d55fff 100644 --- a/src/vs/workbench/contrib/positronNotebook/browser/PositronNotebookEditor.tsx +++ b/src/vs/workbench/contrib/positronNotebook/browser/PositronNotebookEditor.tsx @@ -280,11 +280,6 @@ export class PositronNotebookEditor extends AbstractEditorWithViewState From cebc11987ec7a35ad5b79b073bf944756191a4c2 Mon Sep 17 00:00:00 2001 From: Nick Strayer Date: Fri, 17 Oct 2025 10:22:58 -0400 Subject: [PATCH 2/7] Unskip test --- test/e2e/tests/notebook/notebook-focus-and-selection.test.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/e2e/tests/notebook/notebook-focus-and-selection.test.ts b/test/e2e/tests/notebook/notebook-focus-and-selection.test.ts index 52a6a44c8017..a545cb8aa7cc 100644 --- a/test/e2e/tests/notebook/notebook-focus-and-selection.test.ts +++ b/test/e2e/tests/notebook/notebook-focus-and-selection.test.ts @@ -216,9 +216,8 @@ test.describe('Notebook Focus and Selection', { await notebooksPositron.expectCellIndexToBeSelected(0, { inEditMode: false }); }); - // BUG: https://github.com/posit-dev/positron/issues/9849 // Switch between notebooks to ensure selection is preserved - await test.step.skip('Selection is preserved when switching between editors', async () => { + await test.step('Selection is preserved when switching between editors', async () => { // Switch back to tab 1 and verify selection is still at cell 2 await clickTab(TAB_1); await notebooksPositron.expectCellIndexToBeSelected(2, { inEditMode: false }); From 700520117b08db39cb0d0986990dd1d3f01d338e Mon Sep 17 00:00:00 2001 From: Nick Strayer Date: Fri, 17 Oct 2025 13:53:13 -0400 Subject: [PATCH 3/7] Make sure to keep focus on the correct notebook and also to make sure we actually update the active notebook instance. --- .../IPositronNotebookCell.ts | 5 +++ .../PositronNotebookCell.ts | 3 ++ .../browser/PositronNotebookEditor.tsx | 16 +++++++++ .../browser/PositronNotebookInstance.ts | 35 +++++++++++++++++++ .../browser/positronNotebookService.ts | 11 ++++++ 5 files changed, 70 insertions(+) diff --git a/src/vs/workbench/contrib/positronNotebook/browser/PositronNotebookCells/IPositronNotebookCell.ts b/src/vs/workbench/contrib/positronNotebook/browser/PositronNotebookCells/IPositronNotebookCell.ts index 925011458a88..70f2f53138df 100644 --- a/src/vs/workbench/contrib/positronNotebook/browser/PositronNotebookCells/IPositronNotebookCell.ts +++ b/src/vs/workbench/contrib/positronNotebook/browser/PositronNotebookCells/IPositronNotebookCell.ts @@ -165,6 +165,11 @@ export interface IPositronNotebookCell extends Disposable { */ attachContainer(container: HTMLElement): void; + /** + * Get the container that the cell is attached to + */ + get container(): HTMLElement | undefined; + /** * * @param editor Code editor widget associated with cell. diff --git a/src/vs/workbench/contrib/positronNotebook/browser/PositronNotebookCells/PositronNotebookCell.ts b/src/vs/workbench/contrib/positronNotebook/browser/PositronNotebookCells/PositronNotebookCell.ts index ce40bc69cc3d..3f5d6c511b85 100644 --- a/src/vs/workbench/contrib/positronNotebook/browser/PositronNotebookCells/PositronNotebookCell.ts +++ b/src/vs/workbench/contrib/positronNotebook/browser/PositronNotebookCells/PositronNotebookCell.ts @@ -143,6 +143,9 @@ export abstract class PositronNotebookCellGeneral extends Disposable implements this._container = container; } + get container(): HTMLElement | undefined { + return this._container; + } attachEditor(editor: CodeEditorWidget): void { this._editor.set(editor, undefined); diff --git a/src/vs/workbench/contrib/positronNotebook/browser/PositronNotebookEditor.tsx b/src/vs/workbench/contrib/positronNotebook/browser/PositronNotebookEditor.tsx index f69f53d55fff..ceb76351c7d1 100644 --- a/src/vs/workbench/contrib/positronNotebook/browser/PositronNotebookEditor.tsx +++ b/src/vs/workbench/contrib/positronNotebook/browser/PositronNotebookEditor.tsx @@ -43,6 +43,7 @@ import { URI } from '../../../../base/common/uri.js'; import { isEqual } from '../../../../base/common/resources.js'; import { EditorInput } from '../../../common/editor/editorInput.js'; import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js'; +import { IPositronNotebookService } from './positronNotebookService.js'; /** @@ -91,6 +92,7 @@ export class PositronNotebookEditor extends AbstractEditorWithViewState Date: Fri, 17 Oct 2025 14:08:18 -0400 Subject: [PATCH 4/7] Switch to grabbing instance from active editor rather than from the notebook service --- .../browser/PositronNotebookEditor.tsx | 4 --- .../actionBar/registerCellCommand.ts | 7 +++-- .../positronNotebook/browser/notebookUtils.ts | 28 +++++++++++++++++++ .../browser/positronNotebookService.ts | 11 -------- .../browser/registerNotebookAction.tsx | 15 +++++----- 5 files changed, 39 insertions(+), 26 deletions(-) create mode 100644 src/vs/workbench/contrib/positronNotebook/browser/notebookUtils.ts diff --git a/src/vs/workbench/contrib/positronNotebook/browser/PositronNotebookEditor.tsx b/src/vs/workbench/contrib/positronNotebook/browser/PositronNotebookEditor.tsx index ceb76351c7d1..4089ae68ec3b 100644 --- a/src/vs/workbench/contrib/positronNotebook/browser/PositronNotebookEditor.tsx +++ b/src/vs/workbench/contrib/positronNotebook/browser/PositronNotebookEditor.tsx @@ -43,7 +43,6 @@ import { URI } from '../../../../base/common/uri.js'; import { isEqual } from '../../../../base/common/resources.js'; import { EditorInput } from '../../../common/editor/editorInput.js'; import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js'; -import { IPositronNotebookService } from './positronNotebookService.js'; /** @@ -92,7 +91,6 @@ export class PositronNotebookEditor extends AbstractEditorWithViewState { - const notebookService = accessor.get(IPositronNotebookService); - const activeNotebook = notebookService.getActiveInstance(); + const editorService = accessor.get(IEditorService); + const activeNotebook = getActiveNotebook(editorService); if (!activeNotebook) { return; } diff --git a/src/vs/workbench/contrib/positronNotebook/browser/notebookUtils.ts b/src/vs/workbench/contrib/positronNotebook/browser/notebookUtils.ts new file mode 100644 index 000000000000..ae93e66fcde8 --- /dev/null +++ b/src/vs/workbench/contrib/positronNotebook/browser/notebookUtils.ts @@ -0,0 +1,28 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (C) 2025 Posit Software, PBC. All rights reserved. + * Licensed under the Elastic License 2.0. See LICENSE.txt for license information. + *--------------------------------------------------------------------------------------------*/ + +import { IEditorService } from '../../../services/editor/common/editorService.js'; +import { IPositronNotebookInstance } from './IPositronNotebookInstance.js'; +import { PositronNotebookEditor } from './PositronNotebookEditor.js'; +import { POSITRON_NOTEBOOK_EDITOR_ID } from '../common/positronNotebookCommon.js'; + +/** + * Retrieves the active Positron notebook instance from the editor service. + * + * @param editorService The editor service + * @returns The active notebook instance, or undefined if no Positron notebook is active + */ +export function getActiveNotebook(editorService: IEditorService): IPositronNotebookInstance | undefined { + const activeEditorPane = editorService.activeEditorPane; + + // Check if the active editor is a Positron Notebook Editor + if (!activeEditorPane || activeEditorPane.getId() !== POSITRON_NOTEBOOK_EDITOR_ID) { + return undefined; + } + + // Extract the notebook instance from the editor + const activeNotebook = (activeEditorPane as PositronNotebookEditor).notebookInstance; + return activeNotebook; +} diff --git a/src/vs/workbench/contrib/positronNotebook/browser/positronNotebookService.ts b/src/vs/workbench/contrib/positronNotebook/browser/positronNotebookService.ts index 2c45039534b0..8dc4150beb15 100644 --- a/src/vs/workbench/contrib/positronNotebook/browser/positronNotebookService.ts +++ b/src/vs/workbench/contrib/positronNotebook/browser/positronNotebookService.ts @@ -35,13 +35,6 @@ export interface IPositronNotebookService { */ getActiveInstance(): IPositronNotebookInstance | null; - /** - * Set the currently active notebook instance. - * This should be called when a notebook editor receives focus. - * @param instance The instance to set as active. - */ - setActiveInstance(instance: IPositronNotebookInstance): void; - /** * Register a new notebook instance. * @param instance The instance to register. @@ -101,10 +94,6 @@ class PositronNotebookService extends Disposable implements IPositronNotebookSer return this._activeInstance; } - public setActiveInstance(instance: IPositronNotebookInstance): void { - this._activeInstance = instance; - } - public registerInstance(instance: IPositronNotebookInstance): void { if (!this._instanceById.has(instance.id)) { this._instanceById.set(instance.id, instance); diff --git a/src/vs/workbench/contrib/positronNotebook/browser/registerNotebookAction.tsx b/src/vs/workbench/contrib/positronNotebook/browser/registerNotebookAction.tsx index d5a3393409a1..ee08b7c81a8b 100644 --- a/src/vs/workbench/contrib/positronNotebook/browser/registerNotebookAction.tsx +++ b/src/vs/workbench/contrib/positronNotebook/browser/registerNotebookAction.tsx @@ -13,11 +13,12 @@ import { ContextKeyExpr, ContextKeyExpression } from '../../../../platform/conte import { ServicesAccessor } from '../../../../platform/instantiation/common/instantiation.js'; import { KeybindingsRegistry, KeybindingWeight } from '../../../../platform/keybinding/common/keybindingsRegistry.js'; import { PositronActionBarWidgetRegistry } from '../../../../platform/positronActionBar/browser/positronActionBarWidgetRegistry.js'; -import { IPositronNotebookService } from './positronNotebookService.js'; import { POSITRON_NOTEBOOK_EDITOR_CONTAINER_FOCUSED } from './ContextKeysManager.js'; import { POSITRON_NOTEBOOK_EDITOR_ID } from '../common/positronNotebookCommon.js'; import { IPositronNotebookInstance } from './IPositronNotebookInstance.js'; import { NotebookInstanceProvider } from './NotebookInstanceProvider.js'; +import { IEditorService } from '../../../services/editor/common/editorService.js'; +import { getActiveNotebook } from './notebookUtils.js'; /** * Keybinding configuration for notebook actions. @@ -260,8 +261,8 @@ function registerNotebookCommandInternal(options: INotebookCommandOptions): IDis const commandDisposable = CommandsRegistry.registerCommand({ id: options.commandId, handler: (accessor: ServicesAccessor) => { - const notebookService = accessor.get(IPositronNotebookService); - const activeNotebook = notebookService.getActiveInstance(); + const editorService = accessor.get(IEditorService); + const activeNotebook = getActiveNotebook(editorService); if (!activeNotebook) { return; } @@ -354,11 +355,9 @@ function registerNotebookWidgetInternal(options: INotebookWidgetOptions): IDispo componentFactory: (accessor) => { // Return a wrapper component that provides notebook context return () => { - // Get the active notebook instance from the service - const notebookService = accessor.get(IPositronNotebookService); - const notebook = notebookService.getActiveInstance(); - - // If no active notebook, don't render anything + // Get the active notebook using the VS Code pattern + const editorService = accessor.get(IEditorService); + const notebook = getActiveNotebook(editorService); if (!notebook) { return null; } From 7d11fd836c02021805b018445f5259e37b8ada87 Mon Sep 17 00:00:00 2001 From: Nick Strayer Date: Fri, 17 Oct 2025 14:20:49 -0400 Subject: [PATCH 5/7] Remove all uses of the notebook service active instance getter --- .../browser/SelectPositronNotebookKernelAction.ts | 6 +++--- .../contrib/undoRedo/positronNotebookUndoRedo.ts | 11 ++++++----- .../browser/positronNotebookService.ts | 10 ---------- 3 files changed, 9 insertions(+), 18 deletions(-) diff --git a/src/vs/workbench/contrib/positronNotebook/browser/SelectPositronNotebookKernelAction.ts b/src/vs/workbench/contrib/positronNotebook/browser/SelectPositronNotebookKernelAction.ts index d14ee3b35cfa..1523d2e2576d 100644 --- a/src/vs/workbench/contrib/positronNotebook/browser/SelectPositronNotebookKernelAction.ts +++ b/src/vs/workbench/contrib/positronNotebook/browser/SelectPositronNotebookKernelAction.ts @@ -11,8 +11,9 @@ import { IQuickInputService, IQuickPickItem } from '../../../../platform/quickin import { selectKernelIcon } from '../../notebook/browser/notebookIcons.js'; import { INotebookKernelService, INotebookKernel } from '../../notebook/common/notebookKernelService.js'; import { PositronNotebookInstance } from './PositronNotebookInstance.js'; -import { IPositronNotebookService } from './positronNotebookService.js'; import { POSITRON_RUNTIME_NOTEBOOK_KERNELS_EXTENSION_ID } from '../../runtimeNotebookKernel/common/runtimeNotebookKernelConfig.js'; +import { IEditorService } from '../../../services/editor/common/editorService.js'; +import { getActiveNotebook } from './notebookUtils.js'; export const SELECT_KERNEL_ID_POSITRON = 'positronNotebook.selectKernel'; const NOTEBOOK_ACTIONS_CATEGORY_POSITRON = localize2('positronNotebookActions.category', 'Positron Notebook'); @@ -38,8 +39,7 @@ class SelectPositronNotebookKernelAction extends Action2 { async run(accessor: ServicesAccessor, context?: SelectPositronNotebookKernelContext): Promise { const { forceDropdown } = context || { forceDropdown: false }; const notebookKernelService = accessor.get(INotebookKernelService); - const notebookService = accessor.get(IPositronNotebookService); - const activeNotebook = notebookService.getActiveInstance(); + const activeNotebook = getActiveNotebook(accessor.get(IEditorService)); const quickInputService = accessor.get(IQuickInputService); if (!activeNotebook) { diff --git a/src/vs/workbench/contrib/positronNotebook/browser/contrib/undoRedo/positronNotebookUndoRedo.ts b/src/vs/workbench/contrib/positronNotebook/browser/contrib/undoRedo/positronNotebookUndoRedo.ts index 686d3ece6303..c8436115a545 100644 --- a/src/vs/workbench/contrib/positronNotebook/browser/contrib/undoRedo/positronNotebookUndoRedo.ts +++ b/src/vs/workbench/contrib/positronNotebook/browser/contrib/undoRedo/positronNotebookUndoRedo.ts @@ -6,10 +6,11 @@ import { Disposable } from '../../../../../../base/common/lifecycle.js'; import { WorkbenchPhase, registerWorkbenchContribution2 } from '../../../../../common/contributions.js'; import { UndoCommand, RedoCommand } from '../../../../../../editor/browser/editorExtensions.js'; -import { IPositronNotebookService } from '../../positronNotebookService.js'; import { POSITRON_NOTEBOOK_EDITOR_CONTAINER_FOCUSED, POSITRON_NOTEBOOK_CELL_EDITOR_FOCUSED } from '../../ContextKeysManager.js'; import { IUndoRedoService } from '../../../../../../platform/undoRedo/common/undoRedo.js'; import { IContextKeyService } from '../../../../../../platform/contextkey/common/contextkey.js'; +import { IEditorService } from '../../../../../services/editor/common/editorService.js'; +import { getActiveNotebook } from '../../notebookUtils.js'; class PositronNotebookUndoRedoContribution extends Disposable { @@ -17,7 +18,7 @@ class PositronNotebookUndoRedoContribution extends Disposable { constructor( @IUndoRedoService private readonly undoRedoService: IUndoRedoService, - @IPositronNotebookService private readonly positronNotebookService: IPositronNotebookService, + @IEditorService private readonly editorService: IEditorService, @IContextKeyService private readonly contextKeyService: IContextKeyService ) { super(); @@ -30,7 +31,7 @@ class PositronNotebookUndoRedoContribution extends Disposable { private shouldHandleUndoRedo(): boolean { // Get the active notebook instance to access its scoped context key service - const instance = this.positronNotebookService.getActiveInstance(); + const instance = getActiveNotebook(this.editorService); if (!instance) { return false; } @@ -61,7 +62,7 @@ class PositronNotebookUndoRedoContribution extends Disposable { return false; } - const instance = this.positronNotebookService.getActiveInstance(); + const instance = getActiveNotebook(this.editorService); if (!instance) { return false; } @@ -79,7 +80,7 @@ class PositronNotebookUndoRedoContribution extends Disposable { return false; } - const instance = this.positronNotebookService.getActiveInstance(); + const instance = getActiveNotebook(this.editorService); if (!instance) { return false; } diff --git a/src/vs/workbench/contrib/positronNotebook/browser/positronNotebookService.ts b/src/vs/workbench/contrib/positronNotebook/browser/positronNotebookService.ts index 8dc4150beb15..39ecbc6b7792 100644 --- a/src/vs/workbench/contrib/positronNotebook/browser/positronNotebookService.ts +++ b/src/vs/workbench/contrib/positronNotebook/browser/positronNotebookService.ts @@ -30,11 +30,6 @@ export interface IPositronNotebookService { */ listInstances(uri?: URI): Array; - /** - * Get the currently active notebook instance, if it exists. - */ - getActiveInstance(): IPositronNotebookInstance | null; - /** * Register a new notebook instance. * @param instance The instance to register. @@ -68,7 +63,6 @@ class PositronNotebookService extends Disposable implements IPositronNotebookSer constructor( @IConfigurationService private readonly _configurationService: IConfigurationService ) { - // Call the disposable constrcutor. super(); } @@ -90,10 +84,6 @@ class PositronNotebookService extends Disposable implements IPositronNotebookSer return instances; } - public getActiveInstance(): IPositronNotebookInstance | null { - return this._activeInstance; - } - public registerInstance(instance: IPositronNotebookInstance): void { if (!this._instanceById.has(instance.id)) { this._instanceById.set(instance.id, instance); From 5d29dcdac00343a5db975d50ee8b9129548a6c0f Mon Sep 17 00:00:00 2001 From: Nick Strayer Date: Mon, 20 Oct 2025 11:17:29 -0400 Subject: [PATCH 6/7] Make tab name for untitled notebook a regular expression --- test/e2e/tests/notebook/notebook-focus-and-selection.test.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/e2e/tests/notebook/notebook-focus-and-selection.test.ts b/test/e2e/tests/notebook/notebook-focus-and-selection.test.ts index a545cb8aa7cc..72e89f9947aa 100644 --- a/test/e2e/tests/notebook/notebook-focus-and-selection.test.ts +++ b/test/e2e/tests/notebook/notebook-focus-and-selection.test.ts @@ -191,8 +191,9 @@ test.describe('Notebook Focus and Selection', { const { notebooks, notebooksPositron } = app.workbench; const keyboard = app.code.driver.page.keyboard; - const clickTab = (name: string) => app.code.driver.page.getByRole('tab', { name }).click(); - const TAB_1 = 'Untitled-1.ipynb'; + const clickTab = (name: string | RegExp) => app.code.driver.page.getByRole('tab', { name }).click(); + // Depending on when this test is run, the untitled notebook may have a different number + const TAB_1 = /Untitled-\d+\.ipynb/; const TAB_2 = 'bitmap-notebook.ipynb'; // Start a new notebook (tab 1) From 93e01eeb67168eb89cc10824bdd711568aa5367a Mon Sep 17 00:00:00 2001 From: Nick Strayer Date: Mon, 20 Oct 2025 11:22:57 -0400 Subject: [PATCH 7/7] Rename utility instance getter to match upstream better. --- .../browser/SelectPositronNotebookKernelAction.ts | 4 ++-- .../browser/contrib/undoRedo/positronNotebookUndoRedo.ts | 8 ++++---- .../notebookCells/actionBar/registerCellCommand.ts | 4 ++-- .../contrib/positronNotebook/browser/notebookUtils.ts | 2 +- .../positronNotebook/browser/registerNotebookAction.tsx | 6 +++--- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/vs/workbench/contrib/positronNotebook/browser/SelectPositronNotebookKernelAction.ts b/src/vs/workbench/contrib/positronNotebook/browser/SelectPositronNotebookKernelAction.ts index 1523d2e2576d..d260702e861f 100644 --- a/src/vs/workbench/contrib/positronNotebook/browser/SelectPositronNotebookKernelAction.ts +++ b/src/vs/workbench/contrib/positronNotebook/browser/SelectPositronNotebookKernelAction.ts @@ -13,7 +13,7 @@ import { INotebookKernelService, INotebookKernel } from '../../notebook/common/n import { PositronNotebookInstance } from './PositronNotebookInstance.js'; import { POSITRON_RUNTIME_NOTEBOOK_KERNELS_EXTENSION_ID } from '../../runtimeNotebookKernel/common/runtimeNotebookKernelConfig.js'; import { IEditorService } from '../../../services/editor/common/editorService.js'; -import { getActiveNotebook } from './notebookUtils.js'; +import { getNotebookInstanceFromEditorPane } from './notebookUtils.js'; export const SELECT_KERNEL_ID_POSITRON = 'positronNotebook.selectKernel'; const NOTEBOOK_ACTIONS_CATEGORY_POSITRON = localize2('positronNotebookActions.category', 'Positron Notebook'); @@ -39,7 +39,7 @@ class SelectPositronNotebookKernelAction extends Action2 { async run(accessor: ServicesAccessor, context?: SelectPositronNotebookKernelContext): Promise { const { forceDropdown } = context || { forceDropdown: false }; const notebookKernelService = accessor.get(INotebookKernelService); - const activeNotebook = getActiveNotebook(accessor.get(IEditorService)); + const activeNotebook = getNotebookInstanceFromEditorPane(accessor.get(IEditorService)); const quickInputService = accessor.get(IQuickInputService); if (!activeNotebook) { diff --git a/src/vs/workbench/contrib/positronNotebook/browser/contrib/undoRedo/positronNotebookUndoRedo.ts b/src/vs/workbench/contrib/positronNotebook/browser/contrib/undoRedo/positronNotebookUndoRedo.ts index c8436115a545..3aea384f1198 100644 --- a/src/vs/workbench/contrib/positronNotebook/browser/contrib/undoRedo/positronNotebookUndoRedo.ts +++ b/src/vs/workbench/contrib/positronNotebook/browser/contrib/undoRedo/positronNotebookUndoRedo.ts @@ -10,7 +10,7 @@ import { POSITRON_NOTEBOOK_EDITOR_CONTAINER_FOCUSED, POSITRON_NOTEBOOK_CELL_EDIT import { IUndoRedoService } from '../../../../../../platform/undoRedo/common/undoRedo.js'; import { IContextKeyService } from '../../../../../../platform/contextkey/common/contextkey.js'; import { IEditorService } from '../../../../../services/editor/common/editorService.js'; -import { getActiveNotebook } from '../../notebookUtils.js'; +import { getNotebookInstanceFromEditorPane } from '../../notebookUtils.js'; class PositronNotebookUndoRedoContribution extends Disposable { @@ -31,7 +31,7 @@ class PositronNotebookUndoRedoContribution extends Disposable { private shouldHandleUndoRedo(): boolean { // Get the active notebook instance to access its scoped context key service - const instance = getActiveNotebook(this.editorService); + const instance = getNotebookInstanceFromEditorPane(this.editorService); if (!instance) { return false; } @@ -62,7 +62,7 @@ class PositronNotebookUndoRedoContribution extends Disposable { return false; } - const instance = getActiveNotebook(this.editorService); + const instance = getNotebookInstanceFromEditorPane(this.editorService); if (!instance) { return false; } @@ -80,7 +80,7 @@ class PositronNotebookUndoRedoContribution extends Disposable { return false; } - const instance = getActiveNotebook(this.editorService); + const instance = getNotebookInstanceFromEditorPane(this.editorService); if (!instance) { return false; } diff --git a/src/vs/workbench/contrib/positronNotebook/browser/notebookCells/actionBar/registerCellCommand.ts b/src/vs/workbench/contrib/positronNotebook/browser/notebookCells/actionBar/registerCellCommand.ts index 9d76fc700976..b873003f55d0 100644 --- a/src/vs/workbench/contrib/positronNotebook/browser/notebookCells/actionBar/registerCellCommand.ts +++ b/src/vs/workbench/contrib/positronNotebook/browser/notebookCells/actionBar/registerCellCommand.ts @@ -15,7 +15,7 @@ import { IPositronNotebookInstance } from '../../IPositronNotebookInstance.js'; import { getSelectedCell, getSelectedCells, getEditingCell } from '../../selectionMachine.js'; import { ContextKeyExpr, ContextKeyExpression } from '../../../../../../platform/contextkey/common/contextkey.js'; import { IEditorService } from '../../../../../services/editor/common/editorService.js'; -import { getActiveNotebook } from '../../notebookUtils.js'; +import { getNotebookInstanceFromEditorPane } from '../../notebookUtils.js'; /** * Options for registering a cell command. @@ -82,7 +82,7 @@ export function registerCellCommand({ id: commandId, handler: (accessor: ServicesAccessor) => { const editorService = accessor.get(IEditorService); - const activeNotebook = getActiveNotebook(editorService); + const activeNotebook = getNotebookInstanceFromEditorPane(editorService); if (!activeNotebook) { return; } diff --git a/src/vs/workbench/contrib/positronNotebook/browser/notebookUtils.ts b/src/vs/workbench/contrib/positronNotebook/browser/notebookUtils.ts index ae93e66fcde8..6b20aee15865 100644 --- a/src/vs/workbench/contrib/positronNotebook/browser/notebookUtils.ts +++ b/src/vs/workbench/contrib/positronNotebook/browser/notebookUtils.ts @@ -14,7 +14,7 @@ import { POSITRON_NOTEBOOK_EDITOR_ID } from '../common/positronNotebookCommon.js * @param editorService The editor service * @returns The active notebook instance, or undefined if no Positron notebook is active */ -export function getActiveNotebook(editorService: IEditorService): IPositronNotebookInstance | undefined { +export function getNotebookInstanceFromEditorPane(editorService: IEditorService): IPositronNotebookInstance | undefined { const activeEditorPane = editorService.activeEditorPane; // Check if the active editor is a Positron Notebook Editor diff --git a/src/vs/workbench/contrib/positronNotebook/browser/registerNotebookAction.tsx b/src/vs/workbench/contrib/positronNotebook/browser/registerNotebookAction.tsx index ee08b7c81a8b..b27b38737967 100644 --- a/src/vs/workbench/contrib/positronNotebook/browser/registerNotebookAction.tsx +++ b/src/vs/workbench/contrib/positronNotebook/browser/registerNotebookAction.tsx @@ -18,7 +18,7 @@ import { POSITRON_NOTEBOOK_EDITOR_ID } from '../common/positronNotebookCommon.js import { IPositronNotebookInstance } from './IPositronNotebookInstance.js'; import { NotebookInstanceProvider } from './NotebookInstanceProvider.js'; import { IEditorService } from '../../../services/editor/common/editorService.js'; -import { getActiveNotebook } from './notebookUtils.js'; +import { getNotebookInstanceFromEditorPane } from './notebookUtils.js'; /** * Keybinding configuration for notebook actions. @@ -262,7 +262,7 @@ function registerNotebookCommandInternal(options: INotebookCommandOptions): IDis id: options.commandId, handler: (accessor: ServicesAccessor) => { const editorService = accessor.get(IEditorService); - const activeNotebook = getActiveNotebook(editorService); + const activeNotebook = getNotebookInstanceFromEditorPane(editorService); if (!activeNotebook) { return; } @@ -357,7 +357,7 @@ function registerNotebookWidgetInternal(options: INotebookWidgetOptions): IDispo return () => { // Get the active notebook using the VS Code pattern const editorService = accessor.get(IEditorService); - const notebook = getActiveNotebook(editorService); + const notebook = getNotebookInstanceFromEditorPane(editorService); if (!notebook) { return null; }