From 4400f11596f01275bfd73b63c9f0b15381d6780c Mon Sep 17 00:00:00 2001 From: Jonah Iden Date: Wed, 18 Sep 2024 16:28:54 +0200 Subject: [PATCH] fixed notebook and text editors side by side not being set as active correctly Signed-off-by: Jonah Iden --- .../main/browser/editors-and-documents-main.ts | 17 +++++++++++++++-- .../plugin-ext/src/plugin/notebook/notebooks.ts | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/plugin-ext/src/main/browser/editors-and-documents-main.ts b/packages/plugin-ext/src/main/browser/editors-and-documents-main.ts index 59861414b27c1..f88d72dc27b0b 100644 --- a/packages/plugin-ext/src/main/browser/editors-and-documents-main.ts +++ b/packages/plugin-ext/src/main/browser/editors-and-documents-main.ts @@ -34,7 +34,7 @@ import { DisposableCollection, Emitter, URI } from '@theia/core'; import { EditorManager, EditorWidget } from '@theia/editor/lib/browser'; import { SaveableService } from '@theia/core/lib/browser/saveable-service'; import { TabsMainImpl } from './tabs/tabs-main'; -import { NotebookCellEditorService } from '@theia/notebook/lib/browser'; +import { NotebookCellEditorService, NotebookEditorWidgetService } from '@theia/notebook/lib/browser'; import { SimpleMonacoEditor } from '@theia/monaco/lib/browser/simple-monaco-editor'; export class EditorsAndDocumentsMain implements Disposable { @@ -69,7 +69,11 @@ export class EditorsAndDocumentsMain implements Disposable { this.modelService = container.get(EditorModelService); this.saveResourceService = container.get(SaveableService); - this.stateComputer = new EditorAndDocumentStateComputer(d => this.onDelta(d), this.editorManager, container.get(NotebookCellEditorService), this.modelService, tabsMain); + this.stateComputer = new EditorAndDocumentStateComputer(d => this.onDelta(d), + this.editorManager, + container.get(NotebookCellEditorService), + container.get(NotebookEditorWidgetService), + this.modelService, tabsMain); this.toDispose.push(this.stateComputer); this.toDispose.push(this.onTextEditorAddEmitter); this.toDispose.push(this.onTextEditorRemoveEmitter); @@ -221,6 +225,7 @@ class EditorAndDocumentStateComputer implements Disposable { private callback: (delta: EditorAndDocumentStateDelta) => void, private readonly editorService: EditorManager, private readonly cellEditorService: NotebookCellEditorService, + private readonly notebookWidgetService: NotebookEditorWidgetService, private readonly modelService: EditorModelService, private readonly tabsMain: TabsMainImpl ) { } @@ -245,6 +250,14 @@ class EditorAndDocumentStateComputer implements Disposable { this.toDispose.push(this.cellEditorService.onDidChangeCellEditors(() => this.update())); + this.toDispose.push(this.notebookWidgetService.onDidChangeFocusedEditor(() => { + this.currentState = this.currentState && new EditorAndDocumentState( + this.currentState.documents, + this.currentState.editors, + undefined + ); + })); + for (const widget of this.editorService.all) { this.onTextEditorAdd(widget); } diff --git a/packages/plugin-ext/src/plugin/notebook/notebooks.ts b/packages/plugin-ext/src/plugin/notebook/notebooks.ts index 891354a3b1fdf..5470495d402ec 100644 --- a/packages/plugin-ext/src/plugin/notebook/notebooks.ts +++ b/packages/plugin-ext/src/plugin/notebook/notebooks.ts @@ -335,7 +335,7 @@ export class NotebooksExtImpl implements NotebooksExt { console.error(`FAILED to find active notebook editor ${delta.newActiveEditor}`); } this.activeNotebookEditor = this.editors.get(delta.newActiveEditor); - if (!(this.textDocumentsAndEditors.activeEditor()?.document.uri.path === this.activeNotebookEditor?.notebookData.uri.path)) { + if (this.textDocumentsAndEditors.activeEditor()?.document.uri.path !== this.activeNotebookEditor?.notebookData.uri.path) { this.textDocumentsAndEditors.acceptEditorsAndDocumentsDelta({ newActiveEditor: null });