First class support for initial cursor position in templates

Say you configure an an action with the Create Draft step and a template. Something like this:

When you run this action, the cursor will go to the beginning of the draft (1).

This is problematic because, naturally, your next step is to fill in the template so now you need to move the cursor (2):

It would be more efficient and pleasant if you could define the initial cursor position for the template.

This is already supported with the New Draft with Template action, and since the script is right there, I am sure it can be adopted to build almost anything you can imagine. Still, it would be great to bring this <|> syntax (or similar) into Drafts natively for use within the Create Draft step and maybe elsewhere.

As a bonus feature, it would be next-level if you could configure several cursor positions and jump to them with a keyboard shortcut like Alt and Tab:

Something like this, inspired by vim-snippets:

# Meeting notes [[date]]
Attendees: ${1}
Notes:
  - ${2}

Thank you for your consideration, team! Big fan of your work and Drafts.

By the way, isn’t it a bit odd the cursor starts at the beginning of the template (1)? Syntax to define the initial cursor position aside, wouldn’t it make more sense to put the cursor at the end of the template by default (not illustrated)?

1 Like

With great flexibility comes great configuration, I suppose. The type of things you are talking about are all very possible with Drafts, but because the tool is open-ended, it does not provide opinionated and specific implementations for features as you describe.

Want to set the initial cursor position to the end? Add a one-liner script after your Create Draft step:

editor.setSelectedRange(100000, 0)

(The 10000 is arbitrary, you can set a specific position, but the function will range check beyond the end)

Want to have a system to move between fill-in markers like the ${1} syntax you describe, not very hard to do to create a couple-line scripted actions and assign them keyboard shortcuts to your liking that will navigate in the draft to the next/last instances of matching markers. We can help you with the syntax, but scripting is not as intimidating as you might think.

Heck, if you want to get fancy, you could even customize a syntax definition to highlight your preferred placeholder syntax in color or something.

The beauty of this system is that everyone can get exactly what they want working the way they want. The down-side is that it requires a little setup, you are not just handed a system that prescribes how it should work (and has the inherent limitations of it’s prescription).

3 Likes

The setSelectedRange trick is really neat, and a great example of how versatile and powerful actions can be! Thank you :pray:t2:

Ah, I see what you mean about implementing a custom script.

Can totally appreciate you would need to consider something like this carefully if it can already be accomplished with an extension.

Let me chew on this (maybe try my hand at implementing a script)

In the meantime, thank you very much.