71 / dance

Make your cursors dance with Kakoune-like modal editing in VS Code.
https://marketplace.visualstudio.com/items?itemName=gregoire.dance
ISC License
440 stars 56 forks source link

Rotate selections is order-dependent #322

Closed MaxCross2500 closed 10 months ago

MaxCross2500 commented 10 months ago

All rotate selections commands rotate selections in order of wich they were added, instead of visual order. (This + the fact that add next match command add selection in reverse order results in quite unintuitive behaviour). Is this intended behaviour? (I don't have kakoune, so I don't now how it works in it). If it is, can we at least get alternate commands to rotate selection in visual order, so it would be possible to rebind?

71 commented 10 months ago

Hey, and thanks for the report.

Indeed, that's not great. I couldn't set up selections in an order that would reproduce the issue in Kakoune, but in Helix rotations happen in visual order, not in internal indexing order, so I will change the behavior to that as it does align more to what users would expect.

71 commented 10 months ago

This ended up being more complex than I thought.

The problem is that Kakoune and Helix only seem to care about which selection is the main one. When rotating selections, they only have to update that index, and in the UI this is reflected by having the main selection moving. When rotating contents, they can rotate contents clockwise visually, and since there is only one index to consider when rotating selections, they can perform the same update on the main index integer and that's the end of that.

The problem is that, in Dance, selections are numbered. When rotating selections, it makes sense to rotate them by index rather than by visual position. Sorting them by visual position while maintaining their positions is harder.

This is a breaking change, but I guess the way to go is to rotate selections visually regardless of their actual position, and then to restore their indices. This allows us to stay consistent with rotation of selection contents.

MaxCross2500 commented 10 months ago

I maybe misunderstood, but - shouldn't rotating selections content work by the same logic as rotating selections?

71 commented 10 months ago

@MaxCross2500 Yes, that's right. I probably worded the above message wrong. The way indices interact with order in the document was hard to get right and I wasn't sure there was an approach that could both maintain the order of current selections (wrt indices) and order of the document, but thankfully I found one.