From 4371aa56d3937a8af0bfc9cf7b6e282ab5bb8e9a Mon Sep 17 00:00:00 2001 From: Lost Paul <70213368+LostPaul@users.noreply.github.com> Date: Sat, 27 Jan 2024 12:17:27 +0100 Subject: [PATCH] Fixed hide collapse icon bug & more Fixed that the file explorer always updates when changing a tab in the plugin settings Changed the setting name for the css class that stops white space collapsing for less confusing with the name --- manifest.json | 2 +- src/main.ts | 17 +++++++++----- src/settings/FileExplorerSettings.ts | 4 ++-- src/settings/PathSettings.ts | 35 +++++++++++++--------------- src/settings/SettingsTab.ts | 9 +++++-- 5 files changed, 37 insertions(+), 30 deletions(-) diff --git a/manifest.json b/manifest.json index 2913639..836c231 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "folder-notes", "name": "Folder notes", - "version": "1.7.5", + "version": "1.7.6", "minAppVersion": "0.15.0", "description": "Create notes within folders that can be accessed without collapsing the folder, similar to the functionality offered in Notion.", "author": "Lost Paul", diff --git a/src/main.ts b/src/main.ts index e8a0698..2134016 100644 --- a/src/main.ts +++ b/src/main.ts @@ -22,6 +22,7 @@ export default class FolderNotesPlugin extends Plugin { mouseEvent: MouseEvent | null = null; hoverLinkTriggered = false; tabManager: TabManager; + settingsOpened = false; async onload() { console.log('loading folder notes plugin'); await this.loadSettings(); @@ -38,7 +39,7 @@ export default class FolderNotesPlugin extends Plugin { if (this.settings.boldNameInPath) { document.body.classList.add('folder-note-bold-path'); } if (this.settings.cursiveNameInPath) { document.body.classList.add('folder-note-cursive-path'); } if (this.settings.underlineFolderInPath) { document.body.classList.add('folder-note-underline-path'); } - if (!this.settings.allowWhitespaceCollapsing) { document.body.classList.add('fn-whitespace-stop-collapsing'); } + if (this.settings.stopWhitespaceCollapsing) { document.body.classList.add('fn-whitespace-stop-collapsing'); } if (this.settings.hideCollapsingIcon) { document.body.classList.add('fn-hide-collapse-icon'); } new Commands(this.app, this).registerCommands(); @@ -179,10 +180,10 @@ export default class FolderNotesPlugin extends Plugin { } if (file instanceof TFile) { - const folderName = extractFolderName(this.settings.folderNoteName, file.basename); const folder = getFolder(this, file); if (!(folder instanceof TFolder)) { return; } - if (folderName !== folder.name) { return; } + this.addCSSClassToTitleEL(folder.path, 'has-folder-note'); + this.addCSSClassToTitleEL(file.path, 'is-folder-note'); } if (!this.app.workspace.layoutReady) return; @@ -368,16 +369,18 @@ export default class FolderNotesPlugin extends Plugin { } else if (folder.children.length > 1) { if (attachmentsAreInRootFolder) { return false; - } else if (this.settings.ignoreAttachmentFolder) { + } 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) { if (!folder.collapsed) { this.getEL(folder.path)?.click(); } - return attachmentFolder.children.length <= 2; + return folder.children.length <= 2; } + } else { + return false; } } return true; @@ -532,6 +535,8 @@ export default class FolderNotesPlugin extends Plugin { async saveSettings() { await this.saveData(this.settings); // cleanup any css if we need too + if (!this.settingsOpened) { this.loadFileClasses(true); + } } } diff --git a/src/settings/FileExplorerSettings.ts b/src/settings/FileExplorerSettings.ts index 5663f7e..e4bb85b 100644 --- a/src/settings/FileExplorerSettings.ts +++ b/src/settings/FileExplorerSettings.ts @@ -42,14 +42,14 @@ export async function renderFileExplorer(settingsTab: SettingsTab) { .setDesc('Only open folder notes in the file explorer by clicking on the folder name') .addToggle((toggle) => toggle - .setValue(settingsTab.plugin.settings.allowWhitespaceCollapsing) + .setValue(!settingsTab.plugin.settings.stopWhitespaceCollapsing) .onChange(async (value) => { if (!value) { document.body.classList.add('fn-whitespace-stop-collapsing'); } else { document.body.classList.remove('fn-whitespace-stop-collapsing'); } - settingsTab.plugin.settings.allowWhitespaceCollapsing = value; + settingsTab.plugin.settings.stopWhitespaceCollapsing = !value; await settingsTab.plugin.saveSettings(); }) ); diff --git a/src/settings/PathSettings.ts b/src/settings/PathSettings.ts index 3151503..70ea48f 100644 --- a/src/settings/PathSettings.ts +++ b/src/settings/PathSettings.ts @@ -35,24 +35,22 @@ export async function renderPath(settingsTab: SettingsTab) { settingsTab.settingsPage.createEl('h3', { text: 'Style settings' }); - if (settingsTab.plugin.settings.openFolderNoteOnClickInPath) { - new Setting(containerEl) - .setName('Underline folders in the path') - .setDesc('Add an underline to folders that have a folder note in the path above a note') - .addToggle((toggle) => - toggle - .setValue(settingsTab.plugin.settings.underlineFolderInPath) - .onChange(async (value) => { - settingsTab.plugin.settings.underlineFolderInPath = value; - if (value) { - document.body.classList.add('folder-note-underline-path'); - } else { - document.body.classList.remove('folder-note-underline-path'); - } - await settingsTab.plugin.saveSettings(); - }) - ); - } + new Setting(containerEl) + .setName('Underline folders in the path') + .setDesc('Add an underline to folders that have a folder note in the path above a note') + .addToggle((toggle) => + toggle + .setValue(settingsTab.plugin.settings.underlineFolderInPath) + .onChange(async (value) => { + settingsTab.plugin.settings.underlineFolderInPath = value; + if (value) { + document.body.classList.add('folder-note-underline-path'); + } else { + document.body.classList.remove('folder-note-underline-path'); + } + await settingsTab.plugin.saveSettings(); + }) + ); new Setting(containerEl) .setName('Bold folders in the path') @@ -87,5 +85,4 @@ export async function renderPath(settingsTab: SettingsTab) { await settingsTab.plugin.saveSettings(); }) ); - } \ No newline at end of file diff --git a/src/settings/SettingsTab.ts b/src/settings/SettingsTab.ts index c3ce84c..c00faa9 100644 --- a/src/settings/SettingsTab.ts +++ b/src/settings/SettingsTab.ts @@ -21,7 +21,7 @@ export interface FolderNotesSettings { showDeleteConfirmation: boolean; showRenameConfirmation: boolean; underlineFolder: boolean; - allowWhitespaceCollapsing: boolean; + stopWhitespaceCollapsing: boolean; underlineFolderInPath: boolean; openFolderNoteOnClickInPath: boolean; openInNewTab: boolean; @@ -67,7 +67,7 @@ export const DEFAULT_SETTINGS: FolderNotesSettings = { excludeFolders: [], showDeleteConfirmation: true, underlineFolder: true, - allowWhitespaceCollapsing: false, + stopWhitespaceCollapsing: false, underlineFolderInPath: true, openFolderNoteOnClickInPath: true, openInNewTab: false, @@ -194,6 +194,7 @@ export class SettingsTab extends PluginSettingTab { } display(): void { + this.plugin.settingsOpened = true; const { containerEl } = this; containerEl.empty(); @@ -264,4 +265,8 @@ export class SettingsTab extends PluginSettingTab { }); new Notice('Finished switching storage location'); } + + onClose(): void { + this.plugin.settingsOpened = false; + } }