From 3a2ad4ec722055b35004e57189fa8f434d07c868 Mon Sep 17 00:00:00 2001 From: Aleix Soler Date: Fri, 21 Nov 2025 14:14:21 +0100 Subject: [PATCH] fix: reset editor toolbar badge when active note has no status --- .../toolbar/editorToolbarIntegration.tsx | 40 +++++++++++++++---- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/integrations/toolbar/editorToolbarIntegration.tsx b/integrations/toolbar/editorToolbarIntegration.tsx index dc9e3ba..77c7afd 100644 --- a/integrations/toolbar/editorToolbarIntegration.tsx +++ b/integrations/toolbar/editorToolbarIntegration.tsx @@ -1,6 +1,6 @@ import { createRoot, Root } from "react-dom/client"; import eventBus from "core/eventBus"; -import { MarkdownView, Plugin, WorkspaceLeaf } from "obsidian"; +import { MarkdownView, Plugin, WorkspaceLeaf, TFile } from "obsidian"; import settingsService from "@/core/settingsService"; import { EditorToolbarButton } from "@/components/Toolbar/EditorToolbarButton"; import { NoteStatusService } from "@/core/noteStatusService"; @@ -44,8 +44,8 @@ export class EditorToolbarIntegration { }), ); this.plugin.registerEvent( - this.plugin.app.workspace.on("file-open", () => { - this.handleFileOpen(); + this.plugin.app.workspace.on("file-open", (file) => { + this.handleFileOpen(file); }), ); @@ -155,8 +155,34 @@ export class EditorToolbarIntegration { this.syncButtons(); } - private handleFileOpen() { - this.refreshAllButtons(); + private handleFileOpen(file: TFile | null) { + if (!file) { + this.refreshAllButtons(); + return; + } + + let updatedAny = false; + for (const [leaf, leafButton] of this.leafButtons.entries()) { + const markdownView = leaf.view as MarkdownView; + if (markdownView.file?.path !== file.path) { + continue; + } + + leafButton.noteStatusService = + this.buildNoteStatusServiceForFile(file); + this.renderButtonForLeaf(leafButton); + updatedAny = true; + } + + if (!updatedAny) { + this.refreshAllButtons(); + } + } + + private buildNoteStatusServiceForFile(file: TFile): NoteStatusService { + const noteStatusService = new NoteStatusService(file); + noteStatusService.populateStatuses(); + return noteStatusService; } private createButtonForLeaf(leaf: WorkspaceLeaf) { @@ -370,9 +396,7 @@ export class EditorToolbarIntegration { if (!markdownView.file) { return null; } - const noteStatusService = new NoteStatusService(markdownView.file); - noteStatusService.populateStatuses(); - return noteStatusService; + return this.buildNoteStatusServiceForFile(markdownView.file); } private getUnknownStatusConfig() {