diff --git a/src/main.ts b/src/main.ts index ee94694..ad5bf0b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -84,6 +84,9 @@ export default class FolderNotesPlugin extends Plugin { if (this.settings.hideCollapsingIcon) { document.body.classList.add('fn-hide-collapse-icon'); } + if (this.settings.ignoreAttachmentFolder) { + document.body.classList.add('fn-ignore-attachment-folder'); + } if (!this.settings.highlightFolder) { document.body.classList.add('disable-folder-highlight'); } @@ -433,7 +436,7 @@ export default class FolderNotesPlugin extends Plugin { updateViewDropdown: typeof updateViewDropdown = updateViewDropdown; isEmptyFolderNoteFolder(folder: TFolder): boolean { - const attachmentFolderPath = this.app.vault.getConfig('attachmentFolderPath') as string; + let attachmentFolderPath = this.app.vault.getConfig('attachmentFolderPath') as string; const cleanAttachmentFolderPath = attachmentFolderPath?.replace('./', '') || ''; const attachmentsAreInRootFolder = attachmentFolderPath === './' || attachmentFolderPath === ''; @@ -441,22 +444,27 @@ export default class FolderNotesPlugin extends Plugin { if (folder.children.length === 0) { addCSSClassToFileExplorerEl(folder.path, 'fn-empty-folder', false, this); } + attachmentFolderPath = `${folder.path}/${cleanAttachmentFolderPath}`; if (folder.children.length === threshold) { + addCSSClassToFileExplorerEl(folder.path, 'fn-empty-folder', false, this); return true; } else if (folder.children.length > threshold) { if (attachmentsAreInRootFolder) { return false; - } else if (this.settings.ignoreAttachmentFolder - && this.app.vault.getAbstractFileByPath( - `${folder.path}/${cleanAttachmentFolderPath}`)) { - const folderPath = `${folder.path}/${cleanAttachmentFolderPath}`; - const attachmentFolder = this.app.vault.getAbstractFileByPath(folderPath); - if (attachmentFolder instanceof TFolder - && folder.children.length <= threshold + 1) { - if (!folder.collapsed) { - getFileExplorerElement(folder.path, this)?.click(); - } + } else if ( + this.app.vault.getAbstractFileByPath(attachmentFolderPath) instanceof TFolder + ) { + const attachmentFolder = this.app.vault.getAbstractFileByPath(attachmentFolderPath); + if ( + attachmentFolder instanceof TFolder && + folder.children.length <= threshold + 1 + ) { + addCSSClassToFileExplorerEl(folder.path, 'fn-empty-folder', false, this); + addCSSClassToFileExplorerEl( + folder.path, 'fn-has-attachment-folder', + false, this, + ); } return folder.children.length <= threshold + 1; } diff --git a/src/obsidian-folder-overview b/src/obsidian-folder-overview index 37008ed..69f6e80 160000 --- a/src/obsidian-folder-overview +++ b/src/obsidian-folder-overview @@ -1 +1 @@ -Subproject commit 37008ed555811b06e5e9c3547079368e0cce8113 +Subproject commit 69f6e80b248e6317ca3d9587f27891ce86f55c79 diff --git a/src/settings/FileExplorerSettings.ts b/src/settings/FileExplorerSettings.ts index c69e620..ee9297e 100644 --- a/src/settings/FileExplorerSettings.ts +++ b/src/settings/FileExplorerSettings.ts @@ -135,12 +135,14 @@ export async function renderFileExplorer(settingsTab: SettingsTab): Promise { settingsTab.plugin.settings.hideCollapsingIcon = value; - await settingsTab.plugin.saveSettings(); if (value) { + console.log(document.body.classList.contains('fn-hide-collapse-icon')); document.body.classList.add('fn-hide-collapse-icon'); } else { + console.log(document.body.classList.contains('fn-hide-collapse-icon')); document.body.classList.remove('fn-hide-collapse-icon'); } + await settingsTab.plugin.saveSettings(); settingsTab.display(); }), ); @@ -170,6 +172,11 @@ export async function renderFileExplorer(settingsTab: SettingsTab): Promise { + if (value) { + document.body.classList.add('fn-ignore-attachment-folder'); + } else { + document.body.classList.remove('fn-ignore-attachment-folder'); + } settingsTab.plugin.settings.ignoreAttachmentFolder = value; await settingsTab.plugin.saveSettings(); }), diff --git a/styles.css b/styles.css index 1bfa9ea..84eb68f 100644 --- a/styles.css +++ b/styles.css @@ -223,8 +223,10 @@ li:has(.fv-link-list-item), .fn-has-no-files .collapse-icon, .fn-hide-collapse-icon .has-folder-note.only-has-folder-note .tree-item-icon, -.fn-hide-empty-collapse-icon .fn-empty-folder .tree-item-icon, -.only-has-folder-note:not(.is-collapsed):not(.show-folder-note-in-explorer)>.nav-folder-children { +body.fn-ignore-attachment-folder.fn-hide-collapse-icon .only-has-folder-note .fn-empty-folder.fn-has-attachment-folder .tree-item-icon, +body.fn-hide-collapse-icon .only-has-folder-note .fn-empty-folder:not(.fn-has-attachment-folder) .tree-item-icon, +body.fn-hide-empty-collapse-icon :not(.only-has-folder-note) > .fn-empty-folder:not(.fn-has-attachment-folder) .tree-item-icon, +body.fn-hide-collapse-icon.only-has-folder-note:not(.is-collapsed):not(.show-folder-note-in-explorer)>.nav-folder-children { display: none; }