mirror of
https://github.com/devonthesofa/obsidian-note-status.git
synced 2026-07-22 12:30:24 +00:00
Merge pull request #76 from devonthesofa/fix/bubble-to-non-status
[fix] Reset editor toolbar badge when active note has no status
This commit is contained in:
commit
16bcf02039
1 changed files with 32 additions and 8 deletions
|
|
@ -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() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue