Request: Shortcut to reorder list item
See original GitHub issueExpected Behavior
When moving a list item, I would like to be able to move an item in a (vertical) list up or down without manually shuffling commas and brackets, and knowing where the actual ending comma for this line item is. This could/should also be applied to horizontal lists if this is possible.
Current Behavior
[ "Pear"
, "Apple"
, "Orange"
]
If I want to move paragraph Apple
below Orange
I can press Alt-Down with the cursor and the lines will shuffle, and no manual changes needed.
BUT If I want to swap Pear
and Apple
, i can swap these using Alt-Up/Down. But I then need to replace the initial [
of Pear
with a leading ,
comma, and replace the leading comma from Apple
with a starting bracket.
This is even more a feature that would be great if it would support multiple line content in lists.
[ paragraph
[ Font.bold
, Font.underline
]
[ text "My local fruit collection" ]
, paragraph [] [ text "My fruit company salespitch" ]
]
If I could have my caret on the "paragraph on line 1, and press a key to move it and all implementation down in the list without having to select, move, replace commas and brackets and all that churn work, this would be a fantastic feature in my mind.
[ "Pear", "Apple", "Orange"]
I would also like to be able to move items in such lists with the same shortcut (but it is not a priority). If I have my caret on Orange and press the shortcut I would swap Apple
and Orange
.
Context
Since elm language clients has access to the syntax tree I believe this could be added, but I have no idea how. This feature might actually already exist, but I have not found it. If it does I would be happy to know 😃
Is this an interesting proposal, and is it something that could be contributed if so? And is this a question for the vscode addon or the Elm-LanguageServer?
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top GitHub Comments
I think sending a WIP merge request would be the best way to move forward 😃
I took a shot at how this could be implemented 😄
There are some issues I’m aware of though:
How to handle comments:
Example elm-format formatted code
I think this should move the comments as well if there are any, and this would be easy if the comments were placed within the same list item. But not sure how to handle comments on last line before next list item.
Cursor
The cursor does not follow along, and this makes adding smooth keyboard shortcuts less possible. Not sure if there are any fixes for this. I would have liked to add “Ctrl-Alt-Shift-Up” as a move the current item up in the list, with possibility for repeated keypresses. But I’m not sure if that is possible if the cursor does not follow along.
Currrently all code is within a CodeAction in the Language Server, so it is VSCode independent. I’m not proficient in TypeScript, and hacked this together. If its interesting to add I can try refactoring to something testable.
https://github.com/Strepto/elm-language-server/tree/swaplistitems-codeaction