From ec73ad869f5ce92a9e12886edbfa401aa5fc6973 Mon Sep 17 00:00:00 2001 From: Paul <70213368+LostPaul@users.noreply.github.com> Date: Mon, 1 Jun 2026 17:36:48 +0200 Subject: [PATCH] Fix unwanted auto create of folder for unsupported file types --- src/Commands.ts | 6 +++--- src/events/handleCreate.ts | 4 +++- src/functions/utils.ts | 28 +++++++++++++++++++++------- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/Commands.ts b/src/Commands.ts index 194d0f7..431ca4c 100644 --- a/src/Commands.ts +++ b/src/Commands.ts @@ -128,7 +128,7 @@ export class Commands { id: `create-${type}-folder-note-for-active-file-explorer-folder`, name: `Create ${type} folder note for current active folder in file explorer`, checkCallback: (checking: boolean) => { - const folder = getFileExplorerActiveFolder(); + const folder = getFileExplorerActiveFolder(this.plugin); if (!folder) return false; // Is there already a folder note for the active folder? const folderNote = getFolderNote(this.plugin, folder.path); @@ -162,7 +162,7 @@ export class Commands { id: 'delete-folder-note-of-active-file-explorer-folder', name: 'Delete folder note of current active folder in file explorer', checkCallback: (checking: boolean) => { - const folder = getFileExplorerActiveFolder(); + const folder = getFileExplorerActiveFolder(this.plugin); if (!folder) return false; // Is there any folder note for the active folder? const folderNote = getFolderNote(this.plugin, folder.path); @@ -191,7 +191,7 @@ export class Commands { id: 'open-folder-note-of-active-file-explorer-folder', name: 'Open folder note of current active folder in file explorer', checkCallback: (checking: boolean) => { - const folder = getFileExplorerActiveFolder(); + const folder = getFileExplorerActiveFolder(this.plugin); if (!folder) return false; // Is there any folder note for the active folder? const folderNote = getFolderNote(this.plugin, folder.path); diff --git a/src/events/handleCreate.ts b/src/events/handleCreate.ts index 1d27097..a24c515 100644 --- a/src/events/handleCreate.ts +++ b/src/events/handleCreate.ts @@ -11,6 +11,7 @@ import { removeCSSClassFromFileExplorerEL, addCSSClassToFileExplorerEl, } from 'src/functions/styleFunctions'; +import { isFileInAttachmentFolder } from '@app/functions/utils'; export async function handleCreate(file: TAbstractFile, plugin: FolderNotesPlugin): Promise { if (!plugin.app.workspace.layoutReady) return; @@ -50,7 +51,8 @@ async function handleFileCreation(file: TFile, plugin: FolderNotesPlugin): Promi if (folderNote && folderNote.path === file.path) { addCSSClassToFileExplorerEl(folder.path, 'has-folder-note', false, plugin); addCSSClassToFileExplorerEl(file.path, 'is-folder-note', false, plugin); - } else if (plugin.settings.autoCreateForFiles) { + } else if (plugin.settings.autoCreateForFiles && !isFileInAttachmentFolder(plugin, file)) { + if (!plugin.settings.supportedFileTypes.includes(file.extension)) { return; } if (!file.parent) { return; } const newFolder = await plugin.app.fileManager.createNewFolder(file.parent); turnIntoFolderNote(plugin, file, newFolder); diff --git a/src/functions/utils.ts b/src/functions/utils.ts index 8534d79..4639152 100644 --- a/src/functions/utils.ts +++ b/src/functions/utils.ts @@ -1,4 +1,4 @@ -import { TFolder, TFile, View } from 'obsidian'; +import { TFolder, TFile, View, TAbstractFile } from 'obsidian'; import type { FileExplorerWorkspaceLeaf, FileExplorerView } from 'src/globals'; import { getFolderNote } from './folderNoteFunctions'; import type FolderNotesPlugin from 'src/main'; @@ -37,7 +37,7 @@ export function getFolderPathFromString(path: string): string { } export function getParentFolderPath(path: string): string { - return this.getFolderPathFromString(this.getFolderPathFromString(path)); + return getFolderPathFromString(getFolderPathFromString(path)); } export function getFileExplorer( @@ -71,9 +71,9 @@ export function getFocusedItem(plugin: FolderNotesPlugin): TreeNode