Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request: Shortcut to reorder list item #170

Open
Strepto opened this issue Feb 26, 2021 · 8 comments
Open

Request: Shortcut to reorder list item #170

Strepto opened this issue Feb 26, 2021 · 8 comments
Labels
enhancement New feature or request

Comments

@Strepto
Copy link

Strepto commented Feb 26, 2021

Expected 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?

@razzeee
Copy link
Member

razzeee commented Feb 27, 2021

Maybe elm-format could be able to fix wrongly formatted lists after a move? Not sure if that would work
@avh4

@avh4
Copy link

avh4 commented Feb 27, 2021

Re elm-format, the next version is planned to remove unnecessary commas that are at the beginning or end of a list. But having the initial square bracket be allowed to be a comma instead is something I haven't looked into, and I suspect it would probably make the syntax too ambiguous to parse performantly.

@Strepto
Copy link
Author

Strepto commented Feb 27, 2021

moveactions

I took a shot at how this could be implemented :D

There are some issues I'm aware of though:

How to handle comments:

Example elm-format formatted code

rangeSlider
            -- General List Comment?
            [ -- First item comment
              Html.Attributes.max "11"

            -- Is this commenting the next item?
            , -- Or is this the comment for the next listitem
              onSlide toMsg
            , Html.Attributes.property "val" (Json.Encode.int magnitude)
            ]

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

@razzeee
Copy link
Member

razzeee commented Feb 27, 2021 via email

@Strepto
Copy link
Author

Strepto commented Feb 27, 2021

Yeah, that shouldn't be hard to do. In the server as code action. Probably not as ergonomic as move line up/down via keyboard.

@razzeee I see you replied to the email, I edited the post with a bit more information, and a link to the code I used. As you say the actual CodeAction was not that hard to create, even though its just hacked together.

@razzeee
Copy link
Member

razzeee commented Feb 27, 2021

Code seems good, just some things we can improve, missing tests being the obvious one.

Otherwise we'll nee microsoft/language-server-protocol#724 to make this truly powerful, but I don't see much harm in already shipping it like this.

@Strepto
Copy link
Author

Strepto commented Feb 28, 2021

I took a shot at writing some tests, but could not get them to run correctly. I I'm not proficient enough to fix/understand the boilerplate.

The issue is that "edit" on this line is undefined, and the test throws: https://github.com/elm-tooling/elm-language-server/blob/032707ab925b841d6829140e7f87c3b7c80b9934/test/codeActionTests/codeActionTestBase.ts#L135

@razzeee
Copy link
Member

razzeee commented Feb 28, 2021

I think sending a WIP merge request would be the best way to move forward :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants