typora-issues icon indicating copy to clipboard operation
typora-issues copied to clipboard

[Feature Request] Keystroke to Move Line Up/Down

Open noio opened this issue 7 years ago • 54 comments

A keystroke to move the current line down or up would be incredibly useful for quickly reordering (todo) lists.

Currently (outside of Source Code Mode) it is even hard to swap them manually:

In lieu of a Move Line shortcut I would normally do:

  • Go To Start Of Line (CMD + Left Arrow)
  • Select To End (CMD + SHIFT + Right Arrow)
  • Cut (CMD + X)

But unfortunately that leaves the bullet point or checkbox in place. So I have to fiddle around to remove that manually.

It would be amazing if that was all a single keystroke, of course.

In VSCode, for example:

screen shot 2018-02-01 at 16 31 21

noio avatar Feb 01 '18 15:02 noio

Funny, today I even tried hitting option + arrow up/down to move lines, hoping to see the same behavior as in VSCode, but was not positively surprised xD Nice feature request ;D

pgolebiowski avatar Feb 18 '18 04:02 pgolebiowski

The keystroke would move not a literal line but a Markdown block, right?

This should be easy for leaf blocks (paragraphs, headings), but what to do for a container blocks? The ability to re-ordering list items is probably the most common use-case for re-ordering, but list items are container blocks. How to distinguish the intent to re-order items within a list item (paragraphs or sublists) from moving the entire list item? Lists can have arbitrary nesting depth, so it isn't a matter of a different keystroke for leaf and container block moves.

I think the most common approach by other tools in these situations is to have the following rules:

  1. When the cursor or selection is entirely within a leaf block, move that leaf block.
  2. When the selected text spans multiple leaves, the move action operates on the most immediate (i.e. the smallest) container block containing the selection.
  3. If the leaf is the only child of its parent container, move the parent container. This rule is applies recursively to each parent until a container block with multiple children is encountered.

Another approach is to give list item manipulation (#151) its own keyboard shortcuts. My todo list tool, The Hit List (an awesome tool with the most awesome keyboard shortcuts) has the following for list items:

  • W up
  • S down
  • A left (up a list level)
  • D right (down a list level)

It feels amazingly good to move list items with joystick-like controls.

vassudanagunta avatar Mar 04 '18 16:03 vassudanagunta

I wouldn't mind if it simply reordered literal text lines. I have a good enough conception of the underlying markdown, and if I need to reorder a block, I would normally select the whole block manually (as I would do in a text editor).

But I see the merit of a more advanced method for lists too, especially since there are already multiple issues related specifically to list re-ordering.

EDIT: Come to think of it. I think being able to reorder a literal line might be very convenient because it allows moving a list item from one list to another (passing through headers and paragraphs).

noio avatar Mar 12 '18 14:03 noio

I am currently using the trial version of NotePlan and they solved this problem in a neat way:

First press & hold ⌃+⌘ (Control + Command). This will select the current line. Then keeping the key combination pressed, hit ↑ (up) or ↓ (down) as often as you like. You will see an orange line moving up or down. Release all keys to drop the Todo on the place where you navigated the line to. You can do this with multiple lines as well. Just select as many lines as you need before you start.

nheeren avatar May 16 '18 12:05 nheeren

👍 Is a missing gem - I use this a lot in code editors and SublimeText2. (Along with multi-line editing #907, these are the 2 main reasons I am switching back and forth between Typora and SublimeText)

vertesy avatar Aug 14 '18 20:08 vertesy

👍

njradford avatar Jan 14 '19 18:01 njradford

👍

LewisHides avatar Jan 15 '19 09:01 LewisHides

For fast and destruction-free editing shortcuts for moving logical blocks (h1-h6, p, li, ...) up and down are missing (and required). Copy/Paste or moving a line is something diferent to moving logical blocks:

Moving a heading should move all subsequent parts below with it, moving a paragraph simply moves this single paragraph. moving an item in a list stops at the beginning end and (cherry on the pie) a second "move" changes it to a paragraph.

The keystrokes schould be "single and direct", with nothing to append or to do. Simply "move it" up or down, keeping the structural integrity of the document.

BsNoSi avatar Jan 24 '19 09:01 BsNoSi

It's a good idea to use simple combo-keys to move line up/down. I like alt + ⬆️/⬇️ (option + ⬆️/⬇️ in macOS).

Clarence-pan avatar Feb 12 '19 05:02 Clarence-pan

👍

I personally wouldn't want or expect this to move everything below a heading when moving a heading line, or other such magic, although perhaps that'd be a nice option in the future. I mostly miss this feature for reorganizing lists, especially task lists. (Long-time Sublime Text user here.)

banjerluke avatar Mar 10 '19 20:03 banjerluke

Writing is composing. Writing is editing. Editing and composing include a lot of rearranging.

Rearranging text is a crucial part Typora's entire purpose.

Yet this core-feature suggestion is more than a year old and given no love.

Cut/paste is ok between different programs or documents but it's awkward and frustrating within a document.

A cut and paste operation is almost always more than two steps (fixing markup, undo, redo, etc). It also destroys the contents on the clipboard.

To rearrange things Inside a document there should be a shortcut, just like many mature editors have, as commenters above suggested.

I vote for consistency with Visual Studio Code (ALT+up/down). For moving blocks vs lines, the SHIFT modifier could be used.

I am using Typora for all my writing now and this is the biggest issue I have.

Can we get some love for this feature request?

23min avatar Apr 28 '19 08:04 23min

I want to support the previous comments in that I would not expect this feature to move entire blocks (by default). Moving literal lines (or multiple lines when multiple lines are selected) is flexible and powerful, and allows those lines to be moved through different blocks and list depths. A simple "Move Line" feature should also be easier to implement and less susceptible to bugs.

That said: it is amazing and surprising how central Typora has become to my workflow. Regardless of this missing feature, I use it every day. Who would have thought that a simple WYSIWYG markdown editor is what was missing.

noio avatar Apr 28 '19 09:04 noio

@23min

Yet this core-feature suggestion is more than a year old and given no love.

I may be misreading the tone of your post, but please keep in mind a few things:

  • Not everyone agrees what features are core. There are many in the currently open 268 issues that others would argue are far more core than this one.
    • I'd argue that editing reliability/data integrity, CommonMark conformance, and better WYSIWYG are most important. Typora isn't quite there yet. For example, I continue to have situations where something strange happens, and Undo does almost random things, and I have to revert to the previously saved version. That Undo is not reliable, and the possibility that weird stuff is happening that i don't notice makes me nervous about Typora, as much as I love it.
  • If you've ever developed software, you'd know that what sounds trivial often isn't.
  • We are all using this for free.
  • It's obvious that @abnerlee is putting a lot of time into this, given all the updates. But even if he didn't, he owes us nothing.

We are all using this for free and he owes us nothing.

The proper tone to take isn't demanding 🤨 or entitled 😤, it is begging 😀🙏🏾

vassudanagunta avatar Apr 29 '19 02:04 vassudanagunta

You were misreading :) I was expressing my love.

If this were an open source project I would try to contribute. If I could pay money for it now, I would.

It's not often I'm this enthusiastic about software :)

23min avatar Apr 29 '19 05:04 23min

I have just installed typora and this was one of the first things I tried to do.

I started writing an article, wrote a list of thoughts, looked at my list to see how I'd arrange them within the article, instinctively typed Ctrl+Shift+Up to start rearranging the the list (I usually use Notepad++) and assumed there was a different shortcut, and googled it to reach this thread.

I'm sad the feature doesn't exist yet; any key combination will do. Moving a line up and down seems to me a great feature request, which isn't too 'codey'. It's just a simple way to rearrange anything.

I would favour implimenting it just as it works elsewhere, especially for the benefit of those (who I imagine are a significant minority/majority) moving over from a text editor. i.e. The whole line, or selected lines are moved up or down.

There's no need to overcomplicate anything by forcing nested text to move with headings. That would prevent there being a way of just rearrange the headers within a text, whereas the prefered option would allow you both options, simply widen the selection if you want to keep

E.g. If while editing the heading of Section 2 I realise that the last para of Section 1 better belongs in my newly headed Section 2...

  • with Shortcut-moves-line I can just do Ctrl+Shift+Up, Up, Up
  • with Shortcut-moves-the-section-based-on-the-header-being-moved it's impossible.

crowjake avatar May 08 '20 14:05 crowjake

I vote up for this feature.

As a workaround, for now until it becomes native in Typora, I use below AutoHotKey (Windows) script to do the same function using Alt+Up and Alt+Down:

;Typora, move line up
#IfWinActive, ahk_exe Typora.exe
!Up::
Send {End}{Ctrl down}l{Ctrl up}
Sleep 20
Send {Ctrl down}x{Ctrl up}
Sleep 100
Send {Backspace}
Sleep 20
Send {Home}{Ctrl down}v{Ctrl up}{Shift down}{Enter}{Shift up}{Up}
return

;Typora, move line down
#IfWinActive, ahk_exe Typora.exe
!Down::
Send {End}{Ctrl down}l{Ctrl up}
Sleep 20
Send {Ctrl down}x{Ctrl up}
sleep 100
Send {Del}
Sleep 20
Send {End}{Shift down}{Enter}{Shift up}{Ctrl down}v{Ctrl up}
return

Note Use this keyboard shortcuts in Source Mode (Ctrl+/) as the behavior is not consistent out of source mode

ramisedhom avatar May 14 '20 11:05 ramisedhom

Nice script but not stable. Looses or destroyes content.

BsNoSi avatar May 14 '20 11:05 BsNoSi

Nice try.

I've done something similarly crude and inconsistent just as a macro on my keyboard. It works one line at a time on lists (with source mode off), and bugs out everywhere else, I also can't trigger it too fast or it interrupts itself.

Move current line down:

End → Shift+Home → Ctrl+X → Delete → End → Return → Ctrl+V

Move current line up: (same as before but does it to the line above)

Up → End → Shift+Home → Ctrl+X → Delete → End → Return → Ctrl+V → Up

crowjake avatar May 14 '20 13:05 crowjake

"Move a line" requires reliable identification of a line. This requires structural identification that is not possible with available cursor control shortcuts. Therefore this function has to be integrated into the editor itself if it shall work satisfactory.

BsNoSi avatar May 15 '20 06:05 BsNoSi

Like others, I just installed this and the lack of this feature is a complete non-starter. Being able to quickly rearrange lines (thoughts) is the single most important feature for me. The fact that it hasn't been implemented in over 2 years since this was opened (let alone from the start) is concerning. I'll be looking elsewhere for a markdown editor, which is a shame because it really is beautiful. Perhaps I'll stumble back on Typora some day in the future.

nixsee avatar Jul 01 '20 10:07 nixsee

Thanks Noio for opening this thread...

i've been amazed by Typora in so many ways. Just having a markdown editor that is WYSIWYG for starters, it really validates markdown as an editing choice!! Being able to customise our CSS in Typora is great too

...but yes, this is one feature i use a huge amount in other apps, for example, in both Ms Word and Google Docs, you can move a paragraph up and down with Shift + Alt + up/down. Such a great feature for rapidly sorting a list (eg)

(i know others talk of the simpler Alt + up/down from VSCode... (there are a few different ways of doing it. (I think Bluefish has Ctrl+up/down which is not great because that's needed for navgation)

(Edit: must admit i have zero idea of how to program this feature myself)

anyway, thanks for the discussion and development work michael

mickleberry avatar Jul 18 '20 05:07 mickleberry

As a workaround, for now until it becomes native in Typora, I use below AutoHotKey (Windows) script to do the same function using Alt+Up and Alt+Down:

oh yes, i tried to write an AutoHotKey script as well, so i could use the function across a range of text editors, but i couldn't get it to work consistently :/

mickleberry avatar Jul 18 '20 05:07 mickleberry

I also tried writing a macro in BetterTouchTools for Mac but couldn't get it working reliably. Will have to leave Typora for now as I need this functionality, but I will check back in the future as it's almost perfect in every other way.

patrickrushton avatar Dec 03 '20 15:12 patrickrushton

I'm begging for this function as well.

camxcube avatar Dec 25 '20 04:12 camxcube

This would be an awesome feature. It will maek editing more efficient, for sure!

jaizon2000 avatar Mar 31 '21 01:03 jaizon2000

Everyday I'm wondering why this is still not possible... How difficult could it be, and why is it not the very next thing in the development plan, just... why??? (would love to hear an explanation)

twio142 avatar May 10 '21 07:05 twio142

@abnerlee I don't know if this feature interests you, but if you want another Markdown editor as an inspiration, check iAWriter. Its shortcut to move a line up is ⌘⌥↑ and ⌘⌥↓ to move down.

mikez avatar Jun 01 '21 17:06 mikez

NO – iAWriter is no option as replacement for Typora. It lacks of much features Typora offers. Therefore, I will and can wait for this feature. In compare, iAWriter starts very much slower than Typoara – this is a huge disadvantage. It offers only a small export set, many interesting options are not offered on my target OS (Windows). Comparing directly, iAWriter can not compete with Typora (for me).

BsNoSi avatar Jun 02 '21 09:06 BsNoSi

@BsNoSi I'd like you to hear me differently. My intention was not to suggest using a different editor. My intention was to suggest to @abnerlee that if he wants an inspiration for how to implement "Move Line Up" and "Move Line Down" he can take a look at how iAWriter did it.

mikez avatar Jun 02 '21 09:06 mikez

@mikez ✔ In this case we agree 😊

BsNoSi avatar Jun 02 '21 10:06 BsNoSi