From b8817a56923e3cc59395fe2dd5090cc84b10cded Mon Sep 17 00:00:00 2001 From: Lost Paul <70213368+LostPaul@users.noreply.github.com> Date: Sun, 21 Jan 2024 18:12:15 +0100 Subject: [PATCH] Fix active folder highlight --- src/functions/folderNoteFunctions.ts | 17 +++++++++++++++-- src/main.ts | 4 +++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/functions/folderNoteFunctions.ts b/src/functions/folderNoteFunctions.ts index dbd3712..c54fab9 100644 --- a/src/functions/folderNoteFunctions.ts +++ b/src/functions/folderNoteFunctions.ts @@ -81,12 +81,25 @@ export async function createFolderNote(plugin: FolderNotesPlugin, folderPath: st } file = await plugin.app.vault.create(path, content); } else { - plugin.app.fileManager.renameFile(existingNote, path); file = existingNote; - file.path = path; + await plugin.app.fileManager.renameFile(existingNote, path).then(() => { + file = existingNote; + }); } if (openFile) { + if (plugin.app.workspace.getActiveFile()?.path === path) { + if (plugin.activeFolderDom) { + plugin.activeFolderDom.removeClass('fn-is-active'); + plugin.activeFolderDom = null; + } + + const folder = getFolder(plugin, file); + if (!folder) { return; } + + plugin.activeFolderDom = plugin.getEL(folder.path); + if (plugin.activeFolderDom) plugin.activeFolderDom.addClass('fn-is-active'); + } await leaf.openFile(file); if (plugin.settings.folderNoteType === '.excalidraw' || extension === '.excalidraw') { openExcalidrawView(leaf); diff --git a/src/main.ts b/src/main.ts index 38542e1..9b871d0 100644 --- a/src/main.ts +++ b/src/main.ts @@ -199,10 +199,12 @@ export default class FolderNotesPlugin extends Plugin { this.activeFolderDom.removeClass('fn-is-active'); this.activeFolderDom = null; } + if (!openFile || !openFile.basename) { return; } + const folder = getFolder(this, openFile); if (!folder) { return; } - if (extractFolderName(this.settings.folderNoteName, openFile.basename) !== folder.name) { return; } + this.activeFolderDom = this.getEL(folder.path); if (this.activeFolderDom) this.activeFolderDom.addClass('fn-is-active'); }));