@@ -4,6 +4,9 @@ import invariant from "src/utils/invariant";
44import merge from "three-way-merge" ;
55import type { IChoiceExecutor } from "../IChoiceExecutor" ;
66import {
7+ BASE_FILE_EXTENSION_REGEX ,
8+ CANVAS_FILE_EXTENSION_REGEX ,
9+ MARKDOWN_FILE_EXTENSION_REGEX ,
710 QA_INTERNAL_CAPTURE_TARGET_FILE_PATH ,
811 VALUE_SYNTAX ,
912} from "../constants" ;
@@ -264,17 +267,17 @@ export class CaptureChoiceEngine extends QuickAddChoiceEngine {
264267 ) ;
265268 const resolution = this . resolveCaptureTarget ( formattedCaptureTo ) ;
266269
267- switch ( resolution . kind ) {
268- case "vault" :
269- return this . selectFileInFolder ( "" , true ) ;
270- case "tag" :
271- return this . selectFileWithTag ( resolution . tag ) ;
272- case "folder" :
273- return this . selectFileInFolder ( resolution . folder , false ) ;
274- case "file" :
275- return this . normalizeMarkdownFilePath ( "" , resolution . path ) ;
270+ switch ( resolution . kind ) {
271+ case "vault" :
272+ return this . selectFileInFolder ( "" , true ) ;
273+ case "tag" :
274+ return this . selectFileWithTag ( resolution . tag ) ;
275+ case "folder" :
276+ return this . selectFileInFolder ( resolution . folder , false ) ;
277+ case "file" :
278+ return this . normalizeCaptureFilePath ( resolution . path ) ;
279+ }
276280 }
277- }
278281
279282 private resolveCaptureTarget (
280283 formattedCaptureTo : string ,
@@ -287,7 +290,7 @@ export class CaptureChoiceEngine extends QuickAddChoiceEngine {
287290 // 1) empty => vault picker
288291 // 2) #tag => tag picker
289292 // 3) trailing "/" => folder picker (explicit)
290- // 4) ".md" => file
293+ // 4) known file extension => file
291294 // 5) ambiguous => folder if it exists and no same-name file exists; else file
292295 const normalizedCaptureTo = this . stripLeadingSlash (
293296 formattedCaptureTo . trim ( ) ,
@@ -311,7 +314,11 @@ export class CaptureChoiceEngine extends QuickAddChoiceEngine {
311314 return { kind : "folder" , folder : folderPath } ;
312315 }
313316
314- if ( normalizedCaptureTo . endsWith ( ".md" ) ) {
317+ if (
318+ MARKDOWN_FILE_EXTENSION_REGEX . test ( normalizedCaptureTo ) ||
319+ CANVAS_FILE_EXTENSION_REGEX . test ( normalizedCaptureTo ) ||
320+ BASE_FILE_EXTENSION_REGEX . test ( normalizedCaptureTo )
321+ ) {
315322 return { kind : "file" , path : normalizedCaptureTo } ;
316323 }
317324
@@ -549,7 +556,20 @@ export class CaptureChoiceEngine extends QuickAddChoiceEngine {
549556 this . choice . name ,
550557 ) ;
551558
552- return this . normalizeMarkdownFilePath ( "" , formattedCaptureTo ) ;
559+ return this . normalizeCaptureFilePath ( formattedCaptureTo ) ;
560+ }
561+
562+ private normalizeCaptureFilePath ( path : string ) : string {
563+ const normalizedPath = this . stripLeadingSlash ( path ) ;
564+ if (
565+ MARKDOWN_FILE_EXTENSION_REGEX . test ( normalizedPath ) ||
566+ CANVAS_FILE_EXTENSION_REGEX . test ( normalizedPath ) ||
567+ BASE_FILE_EXTENSION_REGEX . test ( normalizedPath )
568+ ) {
569+ return normalizedPath ;
570+ }
571+
572+ return this . normalizeMarkdownFilePath ( "" , normalizedPath ) ;
553573 }
554574
555575 private mergeCapturePropertyVars ( vars : Map < string , unknown > ) : void {
0 commit comments