Script to create a new entry in a draft made of successive entries

As I said in an earlier post, I work on Drafts in a single draft which is divided by multiple entries as I jot notes along the day. Each entry is separated by ‘***’.

This script creates a new entry in this draft (or any other one), right after the entry where the cursor is. The separator between entries can be set in the ‘Init’ function.

Please find the script in the Directory.

Note: I think that editing a large draft is faster with ‘draft.content’ and ‘draft.update()’ than with ‘editor.setTextInRange()’ etc. I found this testing the script on a heavy draft, but it’s only observation. Would you agree on that ?

[edited] finally, I edited the code in the Directory so that ‘editor.’ is used instead of ‘draft.’. The reason for this is when I insert an entry at the beginning of a long draft, the draft display is scrolled to the end while it should stay at the new entry location. Did not find any other way to avoid this than using ‘editor.’.

For the regexps, the separator was fixed to ‘***’ even if the separator is edited into the variable at the beginning of the script. I corrected this so that the regexps do take into account the separator variable. I had to include a new function RegExp.quote for the regexps to work when the separator includes special regexp chars.