From 8b0df6643f83062b551bdbf7645dbd2c7610c9a8 Mon Sep 17 00:00:00 2001 From: Rob Lourens Date: Fri, 3 Feb 2023 11:10:07 -0800 Subject: [PATCH] Keep notebook kernel bindings for non-untitled notebooks after they close (#173352) And also only persist the selected kernel in the editor view state for untitled notebook editors Fix #171385 --- .../contrib/notebook/browser/notebookEditorWidget.ts | 5 ++++- .../notebook/browser/services/notebookKernelServiceImpl.ts | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts b/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts index 4ee2867f1cb25..690091e518494 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts @@ -88,6 +88,7 @@ import { FloatingClickMenu } from 'vs/workbench/browser/codeeditor'; import { IDimension } from 'vs/editor/common/core/dimension'; import { CellFindMatchModel } from 'vs/workbench/contrib/notebook/browser/contrib/find/findModel'; import { INotebookLoggingService } from 'vs/workbench/contrib/notebook/common/notebookLoggingService'; +import { Schemas } from 'vs/base/common/network'; const $ = DOM.$; @@ -1693,7 +1694,9 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD } } state.contributionsState = contributionsState; - state.selectedKernelId = this.activeKernel?.id; + if (this.textModel?.uri.scheme === Schemas.untitled) { + state.selectedKernelId = this.activeKernel?.id; + } return state; } diff --git a/src/vs/workbench/contrib/notebook/browser/services/notebookKernelServiceImpl.ts b/src/vs/workbench/contrib/notebook/browser/services/notebookKernelServiceImpl.ts index faadb661ad5c6..7eb95b9c0627e 100644 --- a/src/vs/workbench/contrib/notebook/browser/services/notebookKernelServiceImpl.ts +++ b/src/vs/workbench/contrib/notebook/browser/services/notebookKernelServiceImpl.ts @@ -16,6 +16,7 @@ import { IMenu, IMenuService, MenuId } from 'vs/platform/actions/common/actions' import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; import { IAction } from 'vs/base/common/actions'; import { MarshalledId } from 'vs/base/common/marshallingIds'; +import { Schemas } from 'vs/base/common/network'; class KernelInfo { @@ -134,7 +135,7 @@ export class NotebookKernelService extends Disposable implements INotebookKernel this._register(_notebookService.onWillRemoveNotebookDocument(notebook => { const id = NotebookTextModelLikeId.str(notebook); const kernelId = this._notebookBindings.get(id); - if (kernelId) { + if (kernelId && notebook.uri.scheme === Schemas.untitled) { this.selectKernelForNotebook(undefined, notebook); } this._kernelSourceActionsUpdates.get(id)?.dispose();