The Insert Text step should roughly be the equivalent of calling editor.setSelectedText("value");
in script.
See the note from the Editor scripting docs:
NOTE: Generally speaking, editor methods are best used for quick text manipulations of the type used in the extended keyboard. Most substantial updates to draft content are better applied using the
draft
object.
It’s really not a great idea to do any substantial manipulation of draft content using it, or go back and forth between drafts objects and the editor in this way. You can hit timing issues and get otherwise unexpected results. Also, “Insert Text” is making some assumptions about a current cursor position which likely do not make sense out of the context of the Action Bar.
A few suggestions…
1. Keep it in the script:
Use ES6 template literals to ease managing your multiline template variable so you don’t need to use \n
line feeds, like:
let template = `# Heading
Lorem ipsum [[stuff]]
## [[morestuff]]
more text here...`;
d = Draft.create();
d.setTemplateTag(‘stuff’, stuff);
d.setTemplateTag(‘morestuff’, morestuff);
d.content = d.processTemplate(template);
d.update();
editor.load(d);
2. Use “Define Template Tag” step
Use the Define Template Tag step before your script step to create your template, and use the in-context draft
just as a template processor.
So, say you create define template tag step with the name “template”, your script would be:
d = Draft.create();
draft.setTemplateTag(‘stuff’, stuff);
draft.setTemplateTag(‘morestuff’, morestuff);
d.content = draft.processTemplate(template);
d.update();
editor.load(d);
This would work fine as long as you are only using custom template tag, not values from the current draft
.