Support toggling editing of all selections versus only primary selection #10457
Replies: 9 comments
-
We don't support this yet, but kakoune has |
Beta Was this translation helpful? Give feedback.
-
I had forgotten about |
Beta Was this translation helpful? Give feedback.
-
Adding this would also open up the possibility of manually placing cursors without the use of the mouse by turning off multi-cursor control, moving the primary cursor to a location, then pressing |
Beta Was this translation helpful? Give feedback.
-
@Omnikar that's a brilliant foresight! Thinking about the case when you only have one selection and toggle this feature on, how should this behave? On one hand, it has no meaning until you use C to get a new selection. On the other, if we freeze the current selection and immediately spawn a new one on the first movement, we're acting differently than than in the multiple selection case. I'm thinking keep it simple and do the former. Another interesting downstream effect is the meaning of C. If you are using this feature to add cursors, you might expect to make the selection you want then press something to add it to the inactive selections and move on. With C and alt-C, you going the selection above or below instead. Perhaps a ctrl-c binding (do we use this to cancel pipe shells?) to add a new selection to the right of the current selection that is one character wide, and make it the primary pushing what was the primary selection into the list of secondaries. That could generalize to multiple cursors in the edit-all state as well, although it's utility would be considerably more niche, enough to consider only having it in this new edit-primary state. |
Beta Was this translation helpful? Give feedback.
-
Another thought, I believe that most editing primitives assume non-overlapping ranges, and will combine/flatten them if they do. With this, we would need to avoid flattening selections until we toggle back to edit-all state, or push a new non-primary selection (with |
Beta Was this translation helpful? Give feedback.
-
Interesting, when I follow the instructions in your issue, I get:
(After entering insert mode and pressing enter, the selection seems to revert to just the first letter.) helix 22.03 (c18de0e) on elementary OS 6. |
Beta Was this translation helpful? Give feedback.
-
The |
Beta Was this translation helpful? Give feedback.
-
@the-mikedavis Do you know if that’s as designed or a regression? I find it surprising that inserting collapses the selections. I would expect them to remain as per the original instructions. |
Beta Was this translation helpful? Give feedback.
-
I'll have to do a bisect to be sure. It seems like the selections should remain when inserting newlines though. |
Beta Was this translation helpful? Give feedback.
-
One pain point I've had as a kakoune user with regards to multiple cursors is a desire to occasionally modify only one of a set of selections. That is, of like to be able to suspend editing of all but the primary selection, make a modification, then resume editing all of the selections without losing my place.
Motivating Example
I have a list of words that I would like to turn into elements of an array in a JSON document.
I will first select the whole line
x
, surround it with square bracketsms[
, then split on spaceS\s+<enter>
. Now I have a selection for each word, and can further interact to put them on their own linesi<enter><esc>
, and quote themms"
, and finally place a comma after eacha,<esc>
, arriving at the following:This isn't yet valid as the trailing comma on the final array item is not allowed. I could collapse to the primary selection and move over to the comma, replace it with a newline
c<enter><esc>
, but now I've lost the selections I had previously. In this example that doesn't seem so bad but I've come across situations where I want to correct the last item, then continue to act on the set of selections. Often the next operation might be a regex replacement for which I need to have consistent pattern, where the ending brace might cause a problem. Or it might be the opposite of the above example and I need to anchor on the trailing comma but it isn't present on the last selection due to having been properly formatted previously. In any case I often wish to be able to suspend editing of the non-primary selections, correct that one item that breaks the mold, then resume editing all selections.Proposed Interface
Key bindings (up for discussion on better ones)
Alt-,
- when pressed in normal mode, toggle ability to modify all selections. There is a danger here of if you accidentally miss the alt modifier, you lose all but your primary, so it might be better to swap it so that,
is the toggle andalt-,
discards. But then discarding other selections becomes less ergonomic.(
,)
- cycle primary selection to next or previous selection. This is an existing keybind, but would need modification to retain (or just not alter) the state of the above toggle. These are significant because of you are in edit-primary state, you can cycle through the list naturally to make unique edits to every item, before eventually returning to edit-all state.There should be visual feedback of which editing state we are in, by specifying another syntax color for selections that are not being edited. Ideally there would be three color grades:
Obviously this would be up to the color scheme, but we could establish this add an expected pattern to implement in any new ones and revisit the existing.
We may also want to throw a state indicator in the diagnostic line.
Alternatives
One alternative to implementing this feature is to encourage the user to save their selections, collapse to the primary, edit that selection, then restore the previous selections. This was what I did in kakoune using the "marks" feature. To my knowledge, an equivalent feature is not implemented in helix yet. Further, even if it were I would argue that there is still a usability case for this feature over telling people to use marks.
Some evidence for the desire for a feature like this exists in the form of a plugin for kakoune called Phantom selections, which incidentally users marks internally.
Beta Was this translation helpful? Give feedback.
All reactions