How to move cursor to body on file creation?

What I’m trying to do

I am trying to skip focus on title for creating a new note that has <% tp.file.cursor() %> defined in body.

Things I have tried

I have Automatic jump to cursor enabled.
I have Trigger Templater on new file creation enabled.

Contents of the note:

---
creation_date: 
modified_date: 
---
<% tp.file.cursor(1) %>

The note still focuses the title, but with Esc or Enter, goes to the cursor position. I want it to skip the title entirely without the need for an extra keypress.

Adding <%_* setTimeout(() => { app.workspace.activeLeaf.view.editor.focus(); }, 250); -%> at the end of the template works, but that’s yucky and there must be a better solution.

Edit: The same folk from Discord that proposed the above, came in with the solution a while later:

<%*
tp.hooks.on_all_templates_executed(async () => {
  app.workspace.activeLeaf.view.editor.focus();
});
-%>

Just add it at the end of the other template, like so:

<% tp.file.cursor(1) %><%*
tp.hooks.on_all_templates_executed(async () => {
  app.workspace.activeLeaf.view.editor.focus();
});
-%>
1 Like