Skip to content

editor: Add rotation commands for selections and lines#41236

Merged
JosephTLyons merged 1 commit intozed-industries:mainfrom
scorphus:editor-rotate
Dec 9, 2025
Merged

editor: Add rotation commands for selections and lines#41236
JosephTLyons merged 1 commit intozed-industries:mainfrom
scorphus:editor-rotate

Conversation

@scorphus
Copy link
Contributor

@scorphus scorphus commented Oct 26, 2025

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 #5315.

I'm eager to read your thoughts and make any adjustments or improvements to any aspect of this change.

Closes #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:
- 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
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Oct 26, 2025
@scorphus scorphus force-pushed the editor-rotate branch 2 times, most recently from f560730 to cb7aacf Compare October 31, 2025 20:05
@JosephTLyons
Copy link
Collaborator

JosephTLyons commented Dec 4, 2025

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.

@scorphus
Copy link
Contributor Author

scorphus commented Dec 4, 2025

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 ☺️

/// Rotates selections or lines backward.
RotateBackward,
/// Rotates selections or lines forward.
RotateForward,
Copy link
Collaborator

@JosephTLyons JosephTLyons Dec 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Collaborator

@JosephTLyons JosephTLyons Dec 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

DisplayPoint::new(DisplayRow(1), 2)..DisplayPoint::new(DisplayRow(1), 3),
DisplayPoint::new(DisplayRow(2), 2)..DisplayPoint::new(DisplayRow(2), 3),
]
);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@JosephTLyons
Copy link
Collaborator

Hey @scorphus, I think this would be cool to land. You'll need to git rebase main and force push your changes / update your code to work with whatever might've changed in the repo since this PR is open (sorry, I'll try to be more timely on my reviews). I also added some inline comments for a few things I think would improve the changes here.

@scorphus
Copy link
Contributor Author

scorphus commented Dec 9, 2025

Hey @scorphus, I think this would be cool to land. You'll need to git rebase main and force push your changes / update your code to work with whatever might've changed in the repo since this PR is open (sorry, I'll try to be more timely on my reviews). I also added some inline comments for a few things I think would improve the changes here.

The bulk of the conflict was related to the introduction of MultiBufferOffset, which IMO, was a very nice API refinement for type safety 🤩 Happy to fix those conflicts (with a little help from mergiraf ❤️ 🦒 )

Thanks for your comments and insights! I'm ready for more

@JosephTLyons
Copy link
Collaborator

JosephTLyons commented Dec 9, 2025

Thanks for all the updates @scorphus - this is looking good! Thanks for helping us bring more functionality to Zed!

@JosephTLyons JosephTLyons merged commit d5a437d into zed-industries:main Dec 9, 2025
39 of 41 checks passed
@scorphus scorphus deleted the editor-rotate branch December 11, 2025 08:36
@franciskafyi franciskafyi moved this from Community PRs to Done in Quality Week – December 2025 Dec 11, 2025
CherryWorm pushed a commit to CherryWorm/zed that referenced this pull request Dec 16, 2025
…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
someone13574 pushed a commit to someone13574/zed that referenced this pull request Dec 16, 2025
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement

Projects

Development

Successfully merging this pull request may close these issues.

Support transpose selections

2 participants