Set cursor to end of draft in New Linked Draft action

I’m trying to modify the wonderful New Linked Draft action. As written, the action creates a link to a new draft at the cursor position in the current draft.

I’m always forgetting to move the cursor to the end of the TOC draft, and I’d like to have the action automatically reposition the cursor to the end of the draft each time I run it.

Is there a script command to do this? I could probably call another action to do it, but it seems like it would make more sense to just do it in script.

Help please?

If I understand correctly, you want the link inserted at the end, regardless of the current cursor position. To do that, you just need to add a line to move the cursor. Example modification (look for the related block in the existing script, changes noted:

// insert link to new draft in current draft
let newTitle = d.displayTitle;
let linkText = `[[${newTitle}]]`;

// comment out or remove the next line
// let [st, len] = editor.getSelectedRange();
// add below line to move cursor to end...
editor.setSelectedRange(editor.getText().length, 0);

editor.setSelectedText(linkText);
editor.setSelectedRange(st+linkText.length, 0);
``

Excellent! Thanks so much.