Append a New Line From Cursor

I’m new to Drafts but excited to learn hitting a couple stumbling blocks. I like that I can write with my Apple Pen but its not easy to start a new line or bullet point. If I select text the keyboard will open and I can hit Return but that is clunky to the process, I prefer writing when being reflective. The toolbar stays available when writing so I just wanted to add a New Line action but not sure how to do this.

When I insert text it treats it as a template and not a carriage return. I then tried a couple scripts but neither worked.

editor.setSelectedText("\n");

and

editor.setText("\n");

I would think this is simple so perhaps I’m overthinking it but would appreciate any help I could get

Try using an actual new line rather than a “\n” token if by this you mean you are using an Insert text step.

That inserts a new line for me. What does it do for you?

Maybe it is just that it retains the selection that has confused you? If so, you just need to update the cursor position.

editor.setSelectedText("\n");
editor.setSelectedRange(editor.getSelectedRange()[0]+1,0);

The floating Scribble toolbar also includes a new line button (undo|redo|mini keyboard|newline|more) wherever you use it. You can use it in any app that way, but you do get the floating toolbar taking up a bit of extra space on screen.

Hope that helps.

1 Like

That did help thanks. I was stuck on the space being selected (above the new line at that) so moving the cursor addressed the issue. How would you address the this though? When I hit enter on the keyboard when in a list it properly creates the next bullet, but when I use this script it just makes a new line and moves to it.

Ideal Example:

  • Item 1
  • Item 2
  • |

Current Result

  • Item 1
  • Item 2
    |

(no indent though)

Inserting a newline character is not the same as pressing the enter key. The editor is detecting a key press to create the next bullet, not the addition of the character.

You could create a second action for bullet new lines, or you could modify the newline action to insert more content (a bullet and space after the newline) if the line it is appending the newline to begins with a bullet.

The selection functions already used should allow you to get the content of the line where the cursor starts and you can then check for matches.

You might want to incorporate regular expressions to take account of things like nesting of bullets should you use them.

Hope that helps.

In part I realized that from the beginning but I didn’t know what my options were. I had wished that I could just run a macro the pushes the Return key but there is no option to set “Return” in the options.

Anything more complicated I’m not sure how to do and I consider overcomplicated because I would need to account for too many circumstances to cover my intended result. That’s why in my OP I tried to outline my use case in case I wasn’t asking the right question.

I can make you the action, I just want to know a few thing to make it specific and not general (That would be more time spent)

  • What character / characters do you use to set a bullet list?
  • What do you have as preferred indenting?
  • Does any of that changes?
  • When hitting the action in an empty line, do you want it to create a new bullet like the drafts editor or to outdent / delete the bullet?

I appreciate that, if it’s not too much trouble. I’m just trying to enter a new line when writing with my pen. I don’t always need bullets and typically I’m coming from a previous line, I would say I have the following situations

  1. I’m in the middle of a sentence and I want to go to a new line
  2. I’m on the next line and I want another line to start a new paragraph
  3. I’m in the middle of a bulleted list, a line that begins with - for unordered list and 1., 2., 3, etc. for ordered list
  4. I’m at a line that now has a blank bullet and I run it again to remove the bullet and start a new line. I think this answers your last question to outdent / delete the bullet.

I don’t necessarily need indenting for level one list, but I suppose I would need a way to tab and shift+tab to indent deeper list. Typically it’s 4 spaces I think, whatever is standard cause I will likely be copying and pasting content into their actual uses cases after the draft.

Awsome, I’ll work on it on my free time, so it might take me a few days

A while back Greg added a per syntax setting in Drafts (under the editor preferences) for tab key inserts - tab/2 spaces/4 spaces. This is usually the best option to reference in an action to determine how to indent for a user’s setup as it gives the user the control and the consistency.

You can reference this using editor.preferredTabString.

1 Like

@xtremefaith I think is finished, but test it and let me know what you want changes or if you modified anything, or if it’s what you wanted.

Here is the link

1 Like