From d9dd1011f0390523774c70f79c7f4ef9e570c1bc Mon Sep 17 00:00:00 2001 From: AidenLx Date: Tue, 22 Jun 2021 22:37:58 +0800 Subject: [PATCH] fix: fix vault count shown in theme that hide root folder compatible with Minimal and California Coast theme --- src/main.ts | 37 +++++++++++++++++++++++++++++++++++++ src/misc.ts | 1 + src/styles/folder-count.css | 3 +++ 3 files changed, 41 insertions(+) diff --git a/src/main.ts b/src/main.ts index d010d95..f301fea 100644 --- a/src/main.ts +++ b/src/main.ts @@ -2,6 +2,7 @@ import './styles/patch.css'; import { AbstractFileFilter, + rootHiddenClass, showAllNumbersClass, withSubfolderClass, } from 'misc'; @@ -18,6 +19,37 @@ export default class FileExplorerNoteCount extends Plugin { vaultHandler = new VaultHandler(this); + /** compatible with theme that hide root folder */ + doHiddenRoot = (revert = false) => { + if (!this.fileExplorer) { + console.error('file-explorer not found'); + return; + } + const root = this.fileExplorer.fileItems['/']; + const styles = getComputedStyle(root.titleInnerEl); + const setup = () => { + const shouldHide = + styles.display === 'none' || + styles.color === 'rgba(0, 0, 0, 0)'; + root.titleEl.toggleClass(rootHiddenClass, !revert && shouldHide); + }; + if (styles.display !== '') setup(); + else { + let count = 0; + const doId = window.setInterval(() => { + if (count > 10) { + console.error('%o styles empty', root.titleInnerEl); + window.clearInterval(doId); + } else if (styles.display === '') { + count++; + } else { + setup(); + window.clearInterval(doId); + } + }, 100); + } + }; + initialize = (revert = false) => { const leaves = this.app.workspace.getLeavesOfType('file-explorer'); if (leaves.length > 1) console.error('more then one file-explorer'); @@ -26,7 +58,12 @@ export default class FileExplorerNoteCount extends Plugin { if (!this.fileExplorer) this.fileExplorer = leaves[0].view as FileExplorer; setupCount(this, revert); + + this.doHiddenRoot(revert); if (!revert) { + this.registerEvent( + this.app.workspace.on('css-change', this.doHiddenRoot), + ); this.vaultHandler.registerVaultEvent(); if (this.settings.showAllNumbers) document.body.addClass('oz-show-all-num'); diff --git a/src/misc.ts b/src/misc.ts index e03a4b4..9bca943 100644 --- a/src/misc.ts +++ b/src/misc.ts @@ -9,6 +9,7 @@ import { dirname } from 'path-browserify'; export const withSubfolderClass = 'oz-with-subfolder'; export const showAllNumbersClass = 'oz-show-all-num'; +export const rootHiddenClass = 'oz-root-hidden'; export const isFolder = (item: AFItem): item is FolderItem => (item as FolderItem).file instanceof TFolder; diff --git a/src/styles/folder-count.css b/src/styles/folder-count.css index 415034f..bff7e22 100644 --- a/src/styles/folder-count.css +++ b/src/styles/folder-count.css @@ -9,6 +9,9 @@ /* background-color: var(--background-secondary-alt); */ transition: opacity 100ms ease-in-out; } +.nav-folder-title.oz-root-hidden[data-count]::after { + display: none; +} body:not(.oz-show-all-num) .nav-folder:not(.is-collapsed)