Skip to content

Commit

Permalink
Fix active folder highlight
Browse files Browse the repository at this point in the history
  • Loading branch information
LostPaul committed Jan 21, 2024
1 parent 45a43c8 commit b8817a5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
17 changes: 15 additions & 2 deletions src/functions/folderNoteFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}));
Expand Down

0 comments on commit b8817a5

Please sign in to comment.