helix-editor / helix

A post-modern modal text editor.
https://helix-editor.com
Mozilla Public License 2.0
33.74k stars 2.51k forks source link

Consider primary selection with group-transposition #2478

Open Zoybean opened 2 years ago

Zoybean commented 2 years ago

Use primary selection as start point for group-transpose

When providing a count with Alt-( and Alt-), this cycles selections in n tuples, counting from the "top" selection, and ignoring remainders. As an example, with 5 selections, 2 Alt-( will rotate the content of each pair, defining the first pair as the topmost two selections, continuing down the file until there is at most one unpaired selection. My proposal is that rather than starting with the selection at the top of the file, this should start from the primary selection. Example behaviour at the end. The intended usage would be to first use ( and ) to ensure the primary selection is at the start of a tuple before using Alt-( or Alt-), allowing for the current behaviour if it's desired, while also allowing some more unusual layouts of items, without unintuitive behaviour.

Other considerations:

When there is a remainder, it may be difficult to determine where to place the primary selection so that the correct selections are excluded. It seems reasonable in general to expect the user to remove any selections that they do not want affected by a command, so perhaps this command should display a warning and do nothing if there is a remainder (that would otherwise be silently skipped)? This would ensure the user is aware of what selections will be skipped.

Example 1:

With the following selections marked with _, and the primary selection marked ^:

order are words of out these
_____ ^__ _____ __ ___ _____

Desired Behaviour:

2 Alt-) swaps the following pairs (marked with matching brackets):

order are words of out these
____] [__ ____] [_ __] [____
these words are out of order

Current behaviour:

2 Alt-) swaps the following pairs (marked with matching brackets):

order are words of out these
[____ __] [____ _] [__ ____]
are order of words these out

Currently, in order to get the correct word order, this would have to be done in 2 steps:

Example 2:

With the following selections marked with _, and the primary selection marked ^:

order seven are words of out these
_____ _____ ^__ _____ __ ___ _____

Desired Behaviour:

2 Alt-) swaps the following pairs (marked with matching brackets):

order seven are words of out these
____] _____ [__ ____] [_ __] [____
these seven words are out of order

Optionally, the user would be required to deselect seven in addition to placing the primary selection on any of are, of, these.

Current behaviour:

2 Alt-) swaps the following pairs (marked with matching brackets):

order seven are words of out these
[____ ____] [__ ____] [_ __] _____
seven order words are out of these

Currently, in order to get the correct word order, this would have to be done in 2 steps:

EpocSquadron commented 2 years ago

I had no idea this feature even existed. What I would intuitively expect a count provided to those bindings to do is move all the contents like a train and move it by count cars if you will.

Zoybean commented 2 years ago

That's what I had figured at first as well, and in writing the Counts issue I was going to propose your train-car idea; before realising an alternate behaviour might be useful (which, as it turns out, is very close to the current behaviour)