File tree Expand file tree Collapse file tree 2 files changed +17
-11
lines changed Expand file tree Collapse file tree 2 files changed +17
-11
lines changed Original file line number Diff line number Diff line change @@ -17,11 +17,11 @@ export class FileSuggest extends TextInputSuggest<TFile> {
1717 }
1818
1919 renderSuggestion ( file : TFile , el : HTMLElement ) : void {
20- el . setText ( file . name ) ;
20+ el . setText ( file . path ) ;
2121 }
2222
2323 selectSuggestion ( file : TFile ) : void {
24- this . inputEl . value = file . name ;
24+ this . inputEl . value = file . path ;
2525 this . inputEl . trigger ( 'input' ) ;
2626 this . close ( ) ;
2727 }
Original file line number Diff line number Diff line change @@ -69,22 +69,28 @@ export class MediaTypeManager {
6969 }
7070
7171 async getTemplate ( mediaTypeModel : MediaTypeModel , app : App ) : Promise < string > {
72- const templateFileName = this . mediaTemplateMap . get ( mediaTypeModel . getMediaType ( ) ) ;
72+ const templateFilePath = this . mediaTemplateMap . get ( mediaTypeModel . getMediaType ( ) ) ;
7373
74- if ( ! templateFileName ) {
74+ if ( ! templateFilePath ) {
7575 return '' ;
7676 }
7777
78- const templateFile : TFile = app . vault
79- . getFiles ( )
80- . filter ( ( f : TFile ) => f . name === templateFileName )
81- . first ( ) ;
78+ let templateFile = app . vault . getAbstractFileByPath ( templateFilePath ) ;
8279
83- if ( ! templateFile ) {
84- return '' ;
80+ // WARNING: This was previously selected by filename, but that could lead to collisions and unwanted effects.
81+ // This now falls back to the previous method if no file is found
82+ if ( ! templateFile || templateFile instanceof TFolder ) {
83+ templateFile = app . vault
84+ . getFiles ( )
85+ . filter ( ( f : TFile ) => f . name === templateFilePath )
86+ . first ( ) ;
87+
88+ if ( ! templateFile ) {
89+ return '' ;
90+ }
8591 }
8692
87- const template = await app . vault . cachedRead ( templateFile ) ;
93+ const template = await app . vault . cachedRead ( templateFile as TFile ) ;
8894 // console.log(template);
8995 return replaceTags ( template , mediaTypeModel ) ;
9096 }
You can’t perform that action at this time.
0 commit comments