Skip to content

Commit

Permalink
fix: fix vault count shown in theme that hide root folder
Browse files Browse the repository at this point in the history
compatible with Minimal and California Coast theme
  • Loading branch information
aidenlx committed Jun 22, 2021
1 parent bc24533 commit d9dd101
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import './styles/patch.css';

import {
AbstractFileFilter,
rootHiddenClass,
showAllNumbersClass,
withSubfolderClass,
} from 'misc';
Expand All @@ -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');
Expand All @@ -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');
Expand Down
1 change: 1 addition & 0 deletions src/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/styles/folder-count.css
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d9dd101

Please sign in to comment.