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.

4 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.)

@gabrielroth Did you make it work, beacause I have one that works both ways

Hey @Zrapata — if you have this working would you share? I’ve been looking for this feature!

In case it helps, if you have the ThoughtAsylum - Writing action group there are some actions for moving line selections up and down. If the actions above don’t meet your needs, perhaps they might be worth trying. They will move blank lines if part of the current line selection.

TAD-Move Line Selection Up.

Move the lines spanned by the curent selection up in the editor while retaining the existing selection.

TAD-Move Line Selection Down.

Move the lines spanned by the curent selection down in the editor while retaining the existing selection.

Thanks @sylumer, exactly what I need and so many other goodies in there too!

1 Like