Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 33 additions & 4 deletions src/engine/TemplateChoiceEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ export class TemplateChoiceEngine extends TemplateEngine {
const folders: string[] = await this.formatFolderPaths([
...this.choice.folder.folders,
]);
const currentFolder = this.getCurrentFolderSuggestion();
const topItems = currentFolder ? [currentFolder] : [];

if (
this.choice.folder?.chooseFromSubfolders &&
Expand All @@ -262,12 +264,19 @@ export class TemplateChoiceEngine extends TemplateEngine {
return folders.some((f) => folder.startsWith(f));
});

return await this.getOrCreateFolder(subfolders);
return await this.getOrCreateFolder(subfolders, {
allowCreate: true,
allowedRoots: folders,
topItems,
});
}

if (this.choice.folder?.chooseWhenCreatingNote) {
const allFoldersInVault: string[] = getAllFolderPathsInVault(this.app);
return await this.getOrCreateFolder(allFoldersInVault);
return await this.getOrCreateFolder(allFoldersInVault, {
allowCreate: true,
topItems,
});
}

if (this.choice.folder?.createInSameFolderAsActiveFile) {
Expand All @@ -280,9 +289,29 @@ export class TemplateChoiceEngine extends TemplateEngine {
return "";
}

return await this.getOrCreateFolder([activeFile.parent.path]);
return this.getOrCreateFolder([activeFile.parent.path], {
allowCreate: true,
topItems,
});
Comment thread
chhoumann marked this conversation as resolved.
Outdated
}

return await this.getOrCreateFolder(folders);
return await this.getOrCreateFolder(folders, {
allowCreate: true,
allowedRoots: folders,
topItems,
});
}

private getCurrentFolderSuggestion():
| { path: string; label: string }
| null {
const activeFile = this.app.workspace.getActiveFile();
const parent = activeFile?.parent;
if (!activeFile || !parent) return null;
const path = parent.path ?? "";
return {
path,
label: "<current folder>",
};
}
}
Loading