Skip to content

editor: Add align selections action#44769

Merged
SomeoneToIgnore merged 5 commits intozed-industries:mainfrom
tiagolobao:feature/align-cursors
Mar 18, 2026
Merged

editor: Add align selections action#44769
SomeoneToIgnore merged 5 commits intozed-industries:mainfrom
tiagolobao:feature/align-cursors

Conversation

@tiagolobao
Copy link
Copy Markdown
Contributor

@tiagolobao tiagolobao commented Dec 13, 2025

Closes #17090

Hello! This is a feature that I really wanted, so I've created an implementation of it. Hope u guys like it.
It was alto mentioned at this discussion

The use cases were based on the vscode extension (only spaces case was implemented)

  • The algorithm is O(n + m × 2k), where:
    • n = total cursors (for initial analysis, to understand how many alignments will be performed)
    • m = number of alignment columns
    • k = number of alignment rows (first time to get the most-right occurrence, the next one to create the Vec of edits)

Release Notes:

  • Added editor: align selections command

ezgif-524b631d71833ba1


Thank you for creating zed!

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Dec 13, 2025
@tiagolobao tiagolobao force-pushed the feature/align-cursors branch from 94efce4 to eb06cfd Compare December 13, 2025 12:59
@tiagolobao
Copy link
Copy Markdown
Contributor Author

tiagolobao commented Dec 14, 2025

I've just tried to avoid the multiple calls for self.transaction, by calculating the offset that the alignment will cause, but apparently it applies the edits "all at once", then I get this problem:

thread 'main' (44587) panicked at crates/rope/src/chunk.rs:355:13:
point Point(0:9) extends beyond row for string "a      a\n a     a\n  a     a\n  "

I'm sure that the order of the edits: Vec<(Range<Point>, String> are ok, (by column). So I guess I need several transactions for it to work. If I'm missing smth, let me know

@Veykril
Copy link
Copy Markdown
Member

Veykril commented Dec 15, 2025

Not having looked at the PR but you likely will have more luck by using Anchors instead of Points here

@tiagolobao
Copy link
Copy Markdown
Contributor Author

Not having looked at the PR but you likely will have more luck by using Anchors instead of Points here

It worked! thanks for the advice! @Veykril

@Veykril Veykril self-assigned this Dec 16, 2025
@maxdeviant maxdeviant changed the title Feature/align cursors editor: Add align selections action Dec 17, 2025
@Veykril Veykril removed their assignment Jan 5, 2026
@SomeoneToIgnore SomeoneToIgnore self-assigned this Mar 18, 2026
Copy link
Copy Markdown
Contributor

@SomeoneToIgnore SomeoneToIgnore left a comment

Choose a reason for hiding this comment

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

Sorry for the late reply, and thank you for the PR, looks nice.

@SomeoneToIgnore SomeoneToIgnore enabled auto-merge (squash) March 18, 2026 12:47
@SomeoneToIgnore SomeoneToIgnore merged commit c7870cb into zed-industries:main Mar 18, 2026
30 checks passed
AmaanBilwar pushed a commit to AmaanBilwar/zed that referenced this pull request Mar 18, 2026
Closes zed-industries#17090

Hello! This is a feature that I really wanted, so I've created an
implementation of it. Hope u guys like it.
It was alto mentioned at [this
discussion](zed-industries#30473)

The use cases were based on the [vscode
extension](https://marketplace.visualstudio.com/items?itemName=yo1dog.cursor-align)
(only spaces case was implemented)
- The algorithm is O(n + m × 2k), where:
- n = total cursors (for initial analysis, to understand how many
alignments will be performed)
  - m = number of alignment columns  
- k = number of alignment rows (first time to get the most-right
occurrence, the next one to create the `Vec` of edits)


Release Notes:

- Added `editor: align selections` command


![ezgif-524b631d71833ba1](https://github.com/user-attachments/assets/28c3435a-2e01-496f-81c4-721ecfb5b22d)

<br>

Thank you for creating zed!

---------

Co-authored-by: Kirill Bulatov <[email protected]>
AmaanBilwar pushed a commit to AmaanBilwar/zed that referenced this pull request Mar 20, 2026
Closes zed-industries#17090

Hello! This is a feature that I really wanted, so I've created an
implementation of it. Hope u guys like it.
It was alto mentioned at [this
discussion](zed-industries#30473)

The use cases were based on the [vscode
extension](https://marketplace.visualstudio.com/items?itemName=yo1dog.cursor-align)
(only spaces case was implemented)
- The algorithm is O(n + m × 2k), where:
- n = total cursors (for initial analysis, to understand how many
alignments will be performed)
  - m = number of alignment columns  
- k = number of alignment rows (first time to get the most-right
occurrence, the next one to create the `Vec` of edits)


Release Notes:

- Added `editor: align selections` command


![ezgif-524b631d71833ba1](https://github.com/user-attachments/assets/28c3435a-2e01-496f-81c4-721ecfb5b22d)

<br>

Thank you for creating zed!

---------

Co-authored-by: Kirill Bulatov <[email protected]>
toshmukhamedov pushed a commit to toshmukhamedov/zed that referenced this pull request Mar 20, 2026
Closes zed-industries#17090

Hello! This is a feature that I really wanted, so I've created an
implementation of it. Hope u guys like it.
It was alto mentioned at [this
discussion](zed-industries#30473)

The use cases were based on the [vscode
extension](https://marketplace.visualstudio.com/items?itemName=yo1dog.cursor-align)
(only spaces case was implemented)
- The algorithm is O(n + m × 2k), where:
- n = total cursors (for initial analysis, to understand how many
alignments will be performed)
  - m = number of alignment columns  
- k = number of alignment rows (first time to get the most-right
occurrence, the next one to create the `Vec` of edits)


Release Notes:

- Added `editor: align selections` command


![ezgif-524b631d71833ba1](https://github.com/user-attachments/assets/28c3435a-2e01-496f-81c4-721ecfb5b22d)

<br>

Thank you for creating zed!

---------

Co-authored-by: Kirill Bulatov <[email protected]>
AmaanBilwar pushed a commit to AmaanBilwar/zed that referenced this pull request Mar 23, 2026
Closes zed-industries#17090

Hello! This is a feature that I really wanted, so I've created an
implementation of it. Hope u guys like it.
It was alto mentioned at [this
discussion](zed-industries#30473)

The use cases were based on the [vscode
extension](https://marketplace.visualstudio.com/items?itemName=yo1dog.cursor-align)
(only spaces case was implemented)
- The algorithm is O(n + m × 2k), where:
- n = total cursors (for initial analysis, to understand how many
alignments will be performed)
  - m = number of alignment columns  
- k = number of alignment rows (first time to get the most-right
occurrence, the next one to create the `Vec` of edits)


Release Notes:

- Added `editor: align selections` command


![ezgif-524b631d71833ba1](https://github.com/user-attachments/assets/28c3435a-2e01-496f-81c4-721ecfb5b22d)

<br>

Thank you for creating zed!

---------

Co-authored-by: Kirill Bulatov <[email protected]>
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

None yet

Development

Successfully merging this pull request may close these issues.

Command to align cursors

4 participants