Skip to content

Commit 57e43ff

Browse files
committed
fix: preserve explicit capture target file extensions
1 parent 11e6490 commit 57e43ff

File tree

2 files changed

+61
-13
lines changed

2 files changed

+61
-13
lines changed

src/engine/CaptureChoiceEngine.selection.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,4 +264,32 @@ describe("CaptureChoiceEngine capture target resolution", () => {
264264

265265
expect(result).toEqual({ kind: "file", path: "journals" });
266266
});
267+
268+
it("preserves explicit .base capture target paths", async () => {
269+
const app = createApp();
270+
const engine = new CaptureChoiceEngine(
271+
app,
272+
{ settings: { useSelectionAsCaptureValue: false } } as any,
273+
createChoice({ captureTo: "Boards/Kanban.base" }),
274+
createExecutor(),
275+
);
276+
277+
const result = await (engine as any).getFormattedPathToCaptureTo(false);
278+
279+
expect(result).toBe("Boards/Kanban.base");
280+
});
281+
282+
it("preserves explicit .canvas capture target paths", async () => {
283+
const app = createApp();
284+
const engine = new CaptureChoiceEngine(
285+
app,
286+
{ settings: { useSelectionAsCaptureValue: false } } as any,
287+
createChoice({ captureTo: "Boards/Map.canvas" }),
288+
createExecutor(),
289+
);
290+
291+
const result = await (engine as any).getFormattedPathToCaptureTo(false);
292+
293+
expect(result).toBe("Boards/Map.canvas");
294+
});
267295
});

src/engine/CaptureChoiceEngine.ts

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import invariant from "src/utils/invariant";
44
import merge from "three-way-merge";
55
import type { IChoiceExecutor } from "../IChoiceExecutor";
66
import {
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

Comments
 (0)