From cf46b2b60f515cf93e92517817a22d5fb7acfa30 Mon Sep 17 00:00:00 2001 From: xRyul Date: Mon, 13 Jul 2026 07:45:14 +0100 Subject: [PATCH] fix: restore colors for deferred tabs on startup --- main.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/main.ts b/main.ts index 63f3b0d..826b555 100644 --- a/main.ts +++ b/main.ts @@ -287,15 +287,21 @@ export default class ColorTabPlugin extends Plugin { // ── Helpers ─────────────────────────────────────────────────────────────── private getFilePath(leaf: WorkspaceLeaf): string | null { - // Try to get file from view first (most common), then from leaf directly + // Loaded views expose their file directly. const fileFromView = (leaf.view as unknown as { file?: { path: string } }) ?.file; if (fileFromView?.path) return fileFromView.path; - - // Fallback for view types like excalidraw that may store file directly on leaf + + // Excalidraw can store the file directly on the leaf. const fileFromLeaf = (leaf as unknown as { file?: { path: string } }) ?.file; - return fileFromLeaf?.path ?? null; + if (fileFromLeaf?.path) return fileFromLeaf.path; + + // Background tabs can be deferred after startup, leaving view.file unset. + const fileFromState = leaf.getViewState().state?.file; + return typeof fileFromState === "string" && fileFromState.length > 0 + ? fileFromState + : null; } private isColorableLeaf(leaf: WorkspaceLeaf): boolean {