From a027fde4597264e834af90157f6cdabccfaccd8f Mon Sep 17 00:00:00 2001 From: Tim Date: Sun, 30 Apr 2023 05:53:57 +0200 Subject: [PATCH] Cleanup --- .eslintignore | 2 +- src/modules/FolderNoteModule.ts | 32 ++++++++++++++++++-------------- src/types/Utilities.ts | 1 - 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/.eslintignore b/.eslintignore index 353fb4d..8b36e33 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,3 +1,3 @@ npm node_modules build -src/types +src/types/DataEngine.ts diff --git a/src/modules/FolderNoteModule.ts b/src/modules/FolderNoteModule.ts index cb58161..9429d5d 100644 --- a/src/modules/FolderNoteModule.ts +++ b/src/modules/FolderNoteModule.ts @@ -29,34 +29,38 @@ export class FolderNoteModule { // FolderNoteModule.showAllIndexFiles() } - private async onClick(event: MouseEvent) { + private getTargetFromEvent(event: MouseEvent): HTMLElement | null { if (!(event.target instanceof HTMLElement)) { return } - let target = event.target as HTMLElement + const target = event.target // @ts-ignore - This is a hack to get the active plugins. const activePlugins: Set = this.app.plugins.enabledPlugins // Compatibility with https://github.com/ozntel/file-tree-alternative if (activePlugins.has("file-tree-alternative")) { - if (!target.matches(".oz-folder-name, .oz-folder-block")) - return if (target.classList.contains("oz-folder-name")) { - target = target.parentElement + return target.parentElement.parentElement.parentElement } if (target.classList.contains("oz-folder-block")) { - target = target.parentElement.parentElement - } - } else { - // We only want to handle clicks on the folders in the file explorer - if (!target.matches(".nav-folder-title, .nav-folder-title-content")) - return - // If the user clicked on the content of the folder, we need to get the parent element - if (target.classList.contains("nav-folder-title-content")) { - target = event.target.parentElement + return target.parentElement.parentElement } } + // We only want to handle clicks on the folders in the file explorer + if (target.classList.contains("nav-folder-title")) + return target + // If the user clicked on the content of the folder, we need to get the parent element + if (target.classList.contains("nav-folder-title-content")) { + return target.parentElement + } + return null + } + + private async onClick(event: MouseEvent) { + const target = this.getTargetFromEvent(event) + if (target == null) + return // Get the path of the clicked folder const dataPathAttribute = target.attributes.getNamedItem("data-path") diff --git a/src/types/Utilities.ts b/src/types/Utilities.ts index 36ef477..bcbe00b 100644 --- a/src/types/Utilities.ts +++ b/src/types/Utilities.ts @@ -19,7 +19,6 @@ export function isIndexFile(path: string) { } export function isExcludedPath(path: string) { - debugger const pathParts = path.split(/\//) for (const excludedFolder of FolderIndexPlugin.PLUGIN.settings.excludeFolders) { if (excludedFolder == "")