From 34d1c868b4c88672caecbfad060cd02da4f13649 Mon Sep 17 00:00:00 2001 From: PJ Date: Wed, 11 Jan 2023 01:35:36 -0500 Subject: [PATCH] Fix 1.x view headers on new/empty tabs --- manifest.json | 2 +- src/Explorer.tsx | 11 ++++++----- versions.json | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/manifest.json b/manifest.json index d053b39..76067c7 100644 --- a/manifest.json +++ b/manifest.json @@ -3,7 +3,7 @@ "name": "Quick Explorer", "author": "PJ Eby", "authorUrl": "https://github.com/pjeby", - "version": "0.2.7", + "version": "0.2.8", "description": "Perform file explorer operations (and see your current file path) from the title bar, using the mouse or keyboard", "minAppVersion": "0.15.9", "isDesktopOnly": true diff --git a/src/Explorer.tsx b/src/Explorer.tsx index 18e7377..09b1c10 100644 --- a/src/Explorer.tsx +++ b/src/Explorer.tsx @@ -1,4 +1,4 @@ -import { App, FileView, requireApiVersion, TAbstractFile, TFile, TFolder, WorkspaceLeaf } from "./obsidian"; +import { App, FileView, requireApiVersion, TAbstractFile, TFile, TFolder, View, WorkspaceLeaf } from "./obsidian"; import { list, el, mount, unmount } from "redom"; import { ContextMenu } from "./ContextMenu"; import { FolderMenu } from "./FolderMenu"; @@ -127,7 +127,7 @@ export class Explorer extends PerWindowComponent { visibleCrumb(opener: HTMLElement) { let crumb = explorableCrumb(this, opener); if (!opener.isShown()) { - const altOpener = app.workspace.getActiveViewOfType(FileView).containerEl.find( + const altOpener = app.workspace.getActiveViewOfType(View).containerEl.find( ".view-header .view-header-title-parent" ); if (altOpener?.isShown()) { @@ -230,12 +230,13 @@ function tabCrumb(opener: HTMLElement) { const leafEl = opener.matchParent(".workspace-leaf"); let leaf: WorkspaceLeaf, crumb: Breadcrumb; app.workspace.iterateAllLeaves(l => l.containerEl === leafEl && (leaf = l) && true); - const file = (leaf?.view as FileView)?.file; + const root = app.vault.getAbstractFileByPath("/"); + const file = (leaf?.view as FileView)?.file ?? root; const tree = hierarchy(file); const parent = opener.matchParent(".view-header-title-parent"); - crumb = new Breadcrumb(crumbs, parent as HTMLElement, tree.shift().file, onOpen, onClose); + crumb = new Breadcrumb(crumbs, parent as HTMLElement, tree.shift()?.file ?? root, onOpen, onClose); for (const el of parent.findAll(".view-header-breadcrumb")) { - new Breadcrumb(crumbs, el, tree.shift().file, onOpen, onClose); + new Breadcrumb(crumbs, el, tree.shift()?.file ?? root, onOpen, onClose); if (el === opener) crumb = crumbs[crumbs.length-1]; } return crumb; diff --git a/versions.json b/versions.json index a5b96f9..19fecf4 100644 --- a/versions.json +++ b/versions.json @@ -1,5 +1,5 @@ { - "0.2.7": "0.15.9", + "0.2.8": "0.15.9", "0.1.41": "0.15.9", "0.1.37": "0.14.5", "0.1.23": "0.14.2",