[BUG] <% tp.file.cursor() %> doesn't work.
Describe the bug <% tp.file.cursor() %> doesn't work when templating.
To Reproduce Steps to reproduce the behavior:
- create template macro
zettelkastenwith ↓- template path = _template/zettelkasten
- focus new pane = on
- create a file
_template/zettelkastenwith
# <% tp.file.cursor() %>
- execute
QuickAdd: Run QuickAdd->zettelkastenfrom the command palette.
Expected behavior
A file with content # is generated and the cursor position is on the right side of # .
Screenshots If applicable, add screenshots to help explain your problem.
https://user-images.githubusercontent.com/38106890/144574614-9bd873b0-e245-43dc-95da-0b3d7ad78780.mov
Desktop (please complete the following information):
- OS: macOS, Mac mini (M1, 2020)
- Version: Big Sur (v11.6.1)
Fun discovery: if you keep the note title the same, it works the second time you call the quickadd (and add it to your current/existing doc):
# Heading
2022-01-17
- ***cursor is actually here***
# Heading
2022-01-17
- <% tp.file.cursor() %>
it also works if you run it twice and choose "overwrite file"
There seems to be a related bug report over at the Templater repo. It's not clear to me after reading that thread if this is a QuickAdd defect or a Templater design/bug conflict. Maybe a feature request for QuickAdd to place the cursor at the bottom of a new file when it is created? Not sure that's the right design either.
As a workaround for templates added by "capture", I've used a timeout with the command "Templater: Jump to next cursor location". It seems that the QuickAdd insertion logic is still running when the templater tries to set the cursor.
<%*
// Just some modal form
result = await tp.user.modal_form('add_single_example', {title: "Example"})
const title = result.getValue('title');
// I want to get a caption with example
tR += `> [!example] ${title}`
-%>
> <% tp.file.cursor() %>
// Add small timeout, e.g. 100, to finish QuickAdd logics and run command
<%* setTimeout(() => {
app.commands.executeCommandById("templater-obsidian:jump-to-next-cursor-location");
}, 100) -%>