Move line(s) up/down

Two actions, to move the selected line(s) up or down by one line. Attempts to maintain the selection, so you can repeatedly trigger the actions for convenient line-movement.

Up: https://actions.getdrafts.com/a/1HH
Down: https://actions.getdrafts.com/a/1HI

They’re the same script, with just a boolean variable at the top toggled for the direction. There are probably some rough spots in terms of edge cases with blank lines; improvements welcomed.

3 Likes

Thanks for these actions! I’m getting a weird result when the selection includes the very end of a draft—the action pastes my clipboard for some reason.

It’s been a long time since I touched these, but I can take a look. Can you give me a precise example that I can reproduce here?

Correction: It doesn’t seem to have to do with the clipboard. Steps to reproduce:

— Create a new draft
— Type:

one
two
three
[empty line]

i.e. three lines of text followed by a newline.

— Select the word “three” and the newline.
— Trigger the Move Lines Up action.

Expected result: either

one
three
[empty line]
two

or

one
three
two
[empty line]

Actual result:

one
one
two
three
[empty line]

(This is using Drafts 21.1, macOS 10.15.5.)