Prepend text to draft?

There are actions to “insert text” at the cursor, and to “prepend text” to the clipboard, but how can I simply prepend text to the current draft? That is, without copying it to the clipboard and creating a new draft and without manually moving the cursor to the beginning of the draft? Thanks!

Try this script step example. Amend the variable on the first line to the text you wish to insert.

var textToInsert = "insert this at the start: ";

var sel = editor.getSelectedText();
var selRange = editor.getSelectedRange();

draft.content = textToInsert + draft.content;
draft.update();

editor.activate();

if (!sel || sel.length == 0) {
  editor.setSelectedRange(selRange[0]+textToInsert.length,0);
}
else {
  editor.setSelectedRange(selRange[0]+textToInsert.length, selRange[1],0);
}

Here’s an action import URL

Hope that helps get you on the right track.

3 Likes

It works great. Thanks.