mirror of
https://github.com/lostpaul/obsidian-folder-notes.git
synced 2026-07-22 07:40:24 +00:00
Add active class to folder when opening folder note
This commit is contained in:
parent
83b867fc5f
commit
e1e2013eaf
1 changed files with 13 additions and 0 deletions
13
src/main.ts
13
src/main.ts
|
|
@ -10,6 +10,7 @@ export default class FolderNotesPlugin extends Plugin {
|
|||
observer: MutationObserver;
|
||||
settings: FolderNotesSettings;
|
||||
settingsTab: SettingsTab;
|
||||
activeFolderDom: HTMLElement | null;
|
||||
activeFileExplorer: FileExplorerWorkspaceLeaf;
|
||||
|
||||
async onload() {
|
||||
|
|
@ -68,6 +69,17 @@ export default class FolderNotesPlugin extends Plugin {
|
|||
|
||||
}));
|
||||
|
||||
this.registerEvent(this.app.workspace.on('file-open', (openFile: TFile | null) => {
|
||||
if(this.activeFolderDom) {
|
||||
this.activeFolderDom.removeClass('is-active');
|
||||
this.activeFolderDom = null;
|
||||
}
|
||||
if(!openFile || !openFile.basename) { return; }
|
||||
if(openFile.basename !== openFile.parent.name) { return; }
|
||||
this.activeFolderDom = this.getEL(openFile.parent.path);
|
||||
if(this.activeFolderDom) this.activeFolderDom.addClass('is-active');
|
||||
}));
|
||||
|
||||
this.registerEvent(this.app.vault.on('rename', (file: TAbstractFile, oldPath: string) => {
|
||||
if (!this.settings.syncFolderName) {
|
||||
// cleanup after ourselves
|
||||
|
|
@ -326,6 +338,7 @@ export default class FolderNotesPlugin extends Plugin {
|
|||
document.body.classList.remove('folder-note-underline');
|
||||
document.body.classList.remove('hide-folder-note');
|
||||
document.body.classList.remove('fn-whitespace-stop-collapsing');
|
||||
if(this.activeFolderDom) { this.activeFolderDom.removeClass('is-active'); }
|
||||
}
|
||||
|
||||
async loadSettings() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue