quickadd icon indicating copy to clipboard operation
quickadd copied to clipboard

[BUG] Templater code executing twice when using tp.system.prompt to capture user input.

Open romeoleung opened this issue 2 years ago • 7 comments

Describe the bug When enabled Capture format, and inputting templater tp.system.prompt to capture user input, the code will execute twice, and only the 2nd time gets registered.

To Reproduce Steps to reproduce the behavior:

  1. Go to QuickAdd Settings, add a new Capture.
  2. Enable "Capture to active file", enable "Capture format".
  3. In Capture format edit box, input templater code with tp.system.prompt function to get user input. Example:
<%*
let date = await tp.system.prompt('Enter Date:', default_value=tp.date.now('YYYY-MM-DD'), throw_on_cancel=true)
let time = await tp.system.prompt('Enter Time:', default_value=tp.date.now('HH:mm'), throw_on_cancel=true)
%> (@<% date %> <% time %>)
  1. Go back to any notes, and run this QickAdd Capture.
  2. Observe prompts open for a first time - input any valid data, e.g. "2023-09-01" and "17:00", hit Enter to continue.
  3. Observe prompts now open for a 2nd time - input other valid data, e.g. "2024-01-01" and "06:00", hit Enter to continue.
  4. Observe the note, only the 2nd entry is added to the note

Expected behavior The prompts should not display twice. They should display once and the input should be captured and put into the note.

Screenshots If applicable, add screenshots to help explain your problem. Capture 1 - Settings Capture 2 - first date prompt Capture 3 - first time prompt Capture 4 - 2nd date prompt Capture 5 - 2nd time prompt Capture 6 - issue

Desktop (please complete the following information):

  • OS: Windows 10/11
  • Version: Obsidian v1.3.5, QuickAdd V1.2.1

romeoleung avatar Jul 11 '23 07:07 romeoleung

A similar thing happens when I capture to a non-existent daily note that contains various Templater templates.

The Quickadd capture triggers the creation of the daily note, thus triggering Templater (run Templater on new file creation enabled). Like you report, when I fill in the system prompts from Templater, they open once more.

This doesn't happen when I create the daily note outside of Quickadd, only when Quickadd creates the daily note as part of the capture.

FeralFlora avatar Nov 20 '23 10:11 FeralFlora

I'd like to just chime in here that I see this too.

jesperkdab avatar Dec 15 '23 06:12 jesperkdab

Experiencing this as well.

GV-Wong avatar Jan 11 '24 23:01 GV-Wong

Solving this would provide a lot of value to users, because the current situation a big impediment to a good workflow. Whenever you capture to a non-existent daily note that contains Templater prompts, thereby triggering its creation, you have to fill in the prompts twice to get valid results in the resulting note. Of course, this is very inconvenient.

FeralFlora avatar Jan 30 '24 15:01 FeralFlora

FYI for anyone who uses quickadd features sparingly and is looking for a quick minimal solution to this- reverting back to Version 0.17.1 fixes the duplicate prompt templater issue.

GV-Wong avatar Apr 11 '24 22:04 GV-Wong

FYI for anyone who uses quickadd features sparingly and is looking for a quick minimal solution to this- reverting back to Version 0.17.1 fixes the duplicate prompt templater issue.

Very interesting! Maybe that holds some clues as to the cause of this issue. I'm wondering, did you revert version by version to figure this out?

FeralFlora avatar Apr 11 '24 22:04 FeralFlora

FYI for anyone who uses quickadd features sparingly and is looking for a quick minimal solution to this- reverting back to Version 0.17.1 fixes the duplicate prompt templater issue.

Very interesting! Maybe that holds some clues as to the cause of this issue. I'm wondering, did you revert version by version to figure this out?

Read version releases and looked at the code with my limited typescript knowledge.

I didn't look too far into it but I believe it has to do with the templaterParseTemplate function.

My hypothesis is that when templater's own parse_template function is called within that function, it is generating its own instance of the templater object in order to interpret it for rendering. That's why the first entry goes nowhere but the second entry is appended to the current line. This bug started happening around the time of 0.18.3 which involved a fix for rendering templater syntax so it lines up with the timeline.

GV-Wong avatar Apr 12 '24 17:04 GV-Wong