editor: Add rotation commands for selections and lines#41236
editor: Add rotation commands for selections and lines#41236JosephTLyons merged 1 commit intozed-industries:mainfrom
Conversation
Introduces RotateSelectionsForward and RotateSelectionsBackward actions that rotate content in a circular fashion across multiple cursors. Behavior based on context: - With selections: rotates the selected text at each cursor position (e.g., x=1, y=2, z=3 becomes x=3, y=1, z=2) - With just cursors: rotates entire lines at cursor positions (e.g., three lines cycle to line3, line1, line2) Selections are preserved after rotation, allowing repeated cycling. Useful for quickly rearranging values, lines, or arguments. Fixes zed-industries#5315
f560730 to
cb7aacf
Compare
|
Wow, super sorry about this PR hanging around @scorphus, I'm just now noticing it was assigned to me. I'll look over this in the next few days and try to get back on it. Again, sorry for the hold up. |
|
YAY! That's great, @JosephTLyons!! And no worries, I'm glad you're seeing it now. I've been wondering if I should have pinged you or not. I've got a few other cool (to me at least) PRs ready to submit! I'm more than happy to work together and pick which ones are interesting to ship. I'm happy to go at whatever pace works for you |
crates/editor/src/actions.rs
Outdated
| /// Rotates selections or lines backward. | ||
| RotateBackward, | ||
| /// Rotates selections or lines forward. | ||
| RotateForward, |
There was a problem hiding this comment.
I think we could make these a little more verbose to make it a bit more self-documenting about what is being rotated: RotateSelectionsForward / RotateSelectionsBackward
There was a problem hiding this comment.
My thinking here is for readability, but also, we might want to, in the future, add editor: rotate lines {forward,backward} commands that work to rotate all lines within a single selection, that are implemented more like the other line manipulation commands (editor: shuffle lines, editor: sort lines case insensitive). Not something I'd want to see introduced in this PR, but thinking ahead of the possibility.
There was a problem hiding this comment.
I think we could make these a little more verbose to make it a bit more self-documenting about what is being rotated:
RotateSelectionsForward/RotateSelectionsBackward
I renamed the actions a couple of times before evolving the feature as a whole and forgot to revisit those names. Good catch! Thanks
My thinking here is for readability, but also, we might want to, in the future, add
editor: rotate lines {forward,backward}commands that work to rotate all lines within a single selection, that are implemented more like the other line manipulation commands (editor: shuffle lines,editor: sort lines case insensitive). Not something I'd want to see introduced in this PR, but thinking ahead of the possibility.
Gotcha! I'd happily submit a follow-up PR.
crates/editor/src/editor_tests.rs
Outdated
| DisplayPoint::new(DisplayRow(1), 2)..DisplayPoint::new(DisplayRow(1), 3), | ||
| DisplayPoint::new(DisplayRow(2), 2)..DisplayPoint::new(DisplayRow(2), 3), | ||
| ] | ||
| ); |
There was a problem hiding this comment.
After updating to the more modern testing, the last thing I will mention is that, it would be nice if in the case of empty selections, the case where we expand and use the whole row, if we could maintain the same cursor positions, however, I think many of our text manipulation commands end up mutating cursor positions when running them, so if its too challenging to keep the cursors in the position with respect to the text in the selection they are in, it isn't a dealbreaker to getting this merged.
There was a problem hiding this comment.
Thank you for yet another great catch! After a few iterations with different approaches, I think I got to a fairly good implementation using a hash map. Please, LMK if you see space for improvement.
|
Hey @scorphus, I think this would be cool to land. You'll need to |
cb7aacf to
5be95d7
Compare
The bulk of the conflict was related to the introduction of Thanks for your comments and insights! I'm ready for more |
5be95d7 to
02d8c13
Compare
|
Thanks for all the updates @scorphus - this is looking good! Thanks for helping us bring more functionality to Zed! |
…s#41236) Introduces RotateSelectionsForward and RotateSelectionsBackward actions that rotate content in a circular fashion across multiple cursors. Behavior based on context: - With selections: rotates the selected text at each cursor position (e.g., x=1, y=2, z=3 becomes x=3, y=1, z=2) - With just cursors: rotates entire lines at cursor positions (e.g., three lines cycle to line3, line1, line2) Selections are preserved after rotation, allowing repeated cycling. Useful for quickly rearranging values, lines, or arguments. For more examples and use cases, please refer to zed-industries#5315. I'm eager to read your thoughts and make any adjustments or improvements to any aspect of this change. Closes zed-industries#5315 Release Notes: - Added `RotateSelectionsForward` and `RotateSelectionsBackward` actions that rotate content in a circular fashion across multiple cursors
…s#41236) Introduces RotateSelectionsForward and RotateSelectionsBackward actions that rotate content in a circular fashion across multiple cursors. Behavior based on context: - With selections: rotates the selected text at each cursor position (e.g., x=1, y=2, z=3 becomes x=3, y=1, z=2) - With just cursors: rotates entire lines at cursor positions (e.g., three lines cycle to line3, line1, line2) Selections are preserved after rotation, allowing repeated cycling. Useful for quickly rearranging values, lines, or arguments. For more examples and use cases, please refer to zed-industries#5315. I'm eager to read your thoughts and make any adjustments or improvements to any aspect of this change. Closes zed-industries#5315 Release Notes: - Added `RotateSelectionsForward` and `RotateSelectionsBackward` actions that rotate content in a circular fashion across multiple cursors
Introduces RotateSelectionsForward and RotateSelectionsBackward actions that rotate content in a circular fashion across multiple cursors.
Behavior based on context:
Selections are preserved after rotation, allowing repeated cycling. Useful for quickly rearranging values, lines, or arguments.
For more examples and use cases, please refer to #5315.
I'm eager to read your thoughts and make any adjustments or improvements to any aspect of this change.
Closes #5315
Release Notes:
RotateSelectionsForwardandRotateSelectionsBackwardactions that rotate content in a circular fashion across multiple cursors