@@ -248,6 +248,8 @@ export class TemplateChoiceEngine extends TemplateEngine {
248248 const folders : string [ ] = await this . formatFolderPaths ( [
249249 ...this . choice . folder . folders ,
250250 ] ) ;
251+ const currentFolder = this . getCurrentFolderSuggestion ( ) ;
252+ const topItems = currentFolder ? [ currentFolder ] : [ ] ;
251253
252254 if (
253255 this . choice . folder ?. chooseFromSubfolders &&
@@ -262,12 +264,19 @@ export class TemplateChoiceEngine extends TemplateEngine {
262264 return folders . some ( ( f ) => folder . startsWith ( f ) ) ;
263265 } ) ;
264266
265- return await this . getOrCreateFolder ( subfolders ) ;
267+ return await this . getOrCreateFolder ( subfolders , {
268+ allowCreate : true ,
269+ allowedRoots : folders ,
270+ topItems,
271+ } ) ;
266272 }
267273
268274 if ( this . choice . folder ?. chooseWhenCreatingNote ) {
269275 const allFoldersInVault : string [ ] = getAllFolderPathsInVault ( this . app ) ;
270- return await this . getOrCreateFolder ( allFoldersInVault ) ;
276+ return await this . getOrCreateFolder ( allFoldersInVault , {
277+ allowCreate : true ,
278+ topItems,
279+ } ) ;
271280 }
272281
273282 if ( this . choice . folder ?. createInSameFolderAsActiveFile ) {
@@ -280,9 +289,29 @@ export class TemplateChoiceEngine extends TemplateEngine {
280289 return "" ;
281290 }
282291
283- return await this . getOrCreateFolder ( [ activeFile . parent . path ] ) ;
292+ return await this . getOrCreateFolder ( [ activeFile . parent . path ] , {
293+ allowCreate : true ,
294+ topItems,
295+ } ) ;
284296 }
285297
286- return await this . getOrCreateFolder ( folders ) ;
298+ return await this . getOrCreateFolder ( folders , {
299+ allowCreate : true ,
300+ allowedRoots : folders ,
301+ topItems,
302+ } ) ;
303+ }
304+
305+ private getCurrentFolderSuggestion ( ) :
306+ | { path : string ; label : string }
307+ | null {
308+ const activeFile = this . app . workspace . getActiveFile ( ) ;
309+ const parent = activeFile ?. parent ;
310+ if ( ! activeFile || ! parent ) return null ;
311+ const path = parent . path ?? "" ;
312+ return {
313+ path,
314+ label : "<current folder>" ,
315+ } ;
287316 }
288317}
0 commit comments