Skip to content

Commit 7e3a380

Browse files
chhoumannclaude
andcommitted
fix: prevent duplicate prompts when using Templater in Capture choices
When Templater code with tp.system.prompt was used in Capture choices, the prompts would appear twice and only the second response would be used in the note. This change: - Processes Templater code only once during the initial formatting - Prevents secondary processing of the same Templater code - Ensures prompt responses are correctly captured on the first attempt Fixes #533 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent af447c6 commit 7e3a380

File tree

1 file changed

+32
-10
lines changed

1 file changed

+32
-10
lines changed

src/formatters/captureChoiceFormatter.ts

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

30-
const formatted = await this.formatFileContent(input);
31-
const templaterFormatted = templaterParseTemplate(
32-
this.app,
33-
formatted,
34-
this.file,
35-
);
36-
if (!(await templaterFormatted)) return formatted;
37-
38-
return templaterFormatted;
30+
// Skip templater processing here since it's already been processed in formatContentOnly
31+
// Just position the already-formatted content in the file according to settings
32+
const formatted = await this.formatFileContent(input, false);
33+
return formatted;
3934
}
4035

4136
public async formatContent(
@@ -48,10 +43,23 @@ export class CaptureChoiceFormatter extends CompleteFormatter {
4843
return await this.formatFileContent(input);
4944
}
5045

51-
async formatFileContent(input: string): Promise<string> {
46+
async formatFileContent(input: string, runTemplater = true): Promise<string> {
5247
let formatted = await super.formatFileContent(input);
5348
formatted = this.replaceLinebreakInString(formatted);
5449

50+
// If runTemplater is true and we have a file, run the templater parsing
51+
// This will only be true during the first formatting stage (formatContentOnly)
52+
if (runTemplater && this.file) {
53+
const templaterFormatted = await templaterParseTemplate(
54+
this.app,
55+
formatted,
56+
this.file
57+
);
58+
if (templaterFormatted) {
59+
formatted = templaterFormatted;
60+
}
61+
}
62+
5563
const formattedContentIsEmpty = formatted.trim() === "";
5664
if (formattedContentIsEmpty) return this.fileContent;
5765

@@ -81,8 +89,22 @@ export class CaptureChoiceFormatter extends CompleteFormatter {
8189
}
8290

8391
async formatContentOnly(input: string): Promise<string> {
92+
// Process the input with templater (if needed) at this stage
93+
// This is the first pass where we want to run any templater code
8494
let formatted = await super.formatFileContent(input);
8595
formatted = this.replaceLinebreakInString(formatted);
96+
97+
// If we have a file, run templater parsing once in this first pass
98+
if (this.file) {
99+
const templaterFormatted = await templaterParseTemplate(
100+
this.app,
101+
formatted,
102+
this.file
103+
);
104+
if (templaterFormatted) {
105+
formatted = templaterFormatted;
106+
}
107+
}
86108

87109
const formattedContentIsEmpty = formatted.trim() === "";
88110
if (formattedContentIsEmpty) return this.fileContent;

0 commit comments

Comments
 (0)