iPad iOS Widget - Running Action and Cursor Placement

Hi

I have created a simple “insert text” action to create a template dated note. Essentially as follows:

Title

Created: “[[date]]”

Body text

When running the action within drafts, the cursor appears where I need it to - before the word “Body” in the example above. That allows me to immediately create the content of my note.

When running the action from the iOS widget, however, the cursor doesn’t appear until I press on the screen. Is there a fix for that, or am I doing something wrong?

Many thanks in advance for your help

Alex

Not all actions are well suited for use from Widgets (related docs).

For the particular use you describe, you might be better off using the “New Draft with Template” action with template drafts (which also support templates specifying initial cursor position). See:

Just having an action that uses “Insert Text” might have unpredictable results - like inserting in another draft loaded in the editor when executing the action.

Thank you for your response.

I have since noticed it appears as though the ipad isn’t ready to type - it’s if the keyboard isn’t active when I run the action. When pressing the “+” for new draft, it works every time. Are there any tips for ipad keyboard settings when using drafts?

Regarding the “New Draft with Template” action - I love the action, but I’m trying to get to “one press and type” for these notes. Is there a way to use the action within only one template, and bypass the selection menu?

Thank you for all your do with this app. It is incredible.

1 Like

I think I figured it out.

I used this thread to work out which parts to edit from the “New Draft from Template” action - Using prompt results in New Draft with Template

After looking at that, I commented (added “//“ before each like) out the code to be disabled like that person suggested. The script now looks like the below. I’m sure this looks terrible to anyone with experience, but I’m pleased it’s working! I guess I can now delete all the commented code.

Here’s the script:

//modified from New Draft with Template Action

// defaults
let omitFirstLineDefault = false;

// select from a list of drafts tagged “template” and create new draft based on selection.

let f = () => {
// create temp workspace to query drafts
// let workspace = Workspace.create();
// if (!workspace) {
// return false;
// }
// workspace.tagFilter = “template”;
// workspace.setAllSort(“name”, false, true);
// get list of drafts in workspace
// let drafts = workspace.query(“all”);

// check if we found any valid templates

// if (drafts.length == 0) {
// alert(“No templates found. To make templates available to this action, create a draft with the template content and assign it the tag “template”.”);
// return false;
// }

// prompt to select

// let p = Prompt.create();
// p.title = “New Draft with Template”;
// p.message = “Select a template. A new draft will be created based the template selected.”;

// p.addSwitch(“omitTitle”, “Omit First Line in New Draft”, omitFirstLineDefault);

// let ix = 0
// for (let d of drafts) {
// p.addButton(d.displayTitle, ix);
// ix++;
// }

// if (!p.show()) {
// return false;
// }

// get the selected template draft

// let selectedIndex = p.buttonPressed;
// Add the UUID of the Draft to the brackets after Drafts.find

let template = Draft.find('Inserted the UUID here');
let content = template.content;

// let omitTitle = omitFirstLineDefault;

// if (omitTitle) {
// let lines = content.split(’\n’);
// if (lines.length > 0) {
// lines.shift();
// content = lines.join(’\n’).replace(/^\s+/,"");
// }
// }

// create new draft and assign content/tags/syntax
let d = Draft.create();
for (let tag of template.tags) {
	if (tag != "template") {
		d.addTag(tag);
	}
}
d.languageGrammar = template.languageGrammar;
d.content = d.processTemplate(content);
d.update();
// load new draft
editor.load(d);
editor.activate();

// look for <|> to set cursor location
let loc = d.content.search("<|>");

// if (p != -1) {
editor.setText(editor.getText().replace("<|>", “”));
editor.setSelectedRange(loc, 0);
// }

return true;

}

if (app.isPro) {
if (!f()) {
context.cancel();
}
}
else {
alert(“Drafts Pro features required to use this action.”)
}