Skip to content

Commit d9a9bfc

Browse files
authored
Merge pull request #806 from chhoumann/fix/templater-commands-execution
fix: ensure templater commands execute correctly with all capture settings
2 parents 3ead80e + 76a8438 commit d9a9bfc

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

src/formatters/captureChoiceFormatter.ts

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ export class CaptureChoiceFormatter extends CompleteFormatter {
2828
this.fileContent = fileContent;
2929
if (!choice || !file || fileContent === null) return input;
3030

31-
// Skip templater processing here since it's already been processed in formatContentOnly
32-
// Just position the already-formatted content in the file according to settings
33-
const formatted = await this.formatFileContent(input, false);
31+
// Process templater here if we're using insert after or prepend or not capturing to active file
32+
// This is needed because in these cases, the content won't be processed by templaterParseTemplate in CaptureChoiceEngine
33+
const shouldRunTemplater = choice.insertAfter.enabled || choice.prepend || !choice.captureToActiveFile;
34+
const formatted = await this.formatFileContent(input, shouldRunTemplater);
3435
return formatted;
3536
}
3637

@@ -49,7 +50,6 @@ export class CaptureChoiceFormatter extends CompleteFormatter {
4950
formatted = this.replaceLinebreakInString(formatted);
5051

5152
// If runTemplater is true and we have a file, run the templater parsing
52-
// This will only be true during the first formatting stage (formatContentOnly)
5353
if (runTemplater && this.file) {
5454
const templaterFormatted = await templaterParseTemplate(
5555
this.app,
@@ -95,17 +95,10 @@ export class CaptureChoiceFormatter extends CompleteFormatter {
9595
let formatted = await super.formatFileContent(input);
9696
formatted = this.replaceLinebreakInString(formatted);
9797

98-
// If we have a file, run templater parsing once in this first pass
99-
if (this.file) {
100-
const templaterFormatted = await templaterParseTemplate(
101-
this.app,
102-
formatted,
103-
this.file
104-
);
105-
if (templaterFormatted) {
106-
formatted = templaterFormatted;
107-
}
108-
}
98+
// DON'T run templater parsing here - it will be handled either by:
99+
// 1. CaptureChoiceEngine.run() for the active file + no insert after + no prepend case
100+
// 2. formatContentWithFile() for all other cases
101+
// This avoids double processing of templater commands
109102

110103
const formattedContentIsEmpty = formatted.trim() === "";
111104
if (formattedContentIsEmpty) return this.fileContent;

0 commit comments

Comments
 (0)