Skip to content

editor: Autoscroll to initial selection on select all matches edit#49232

Merged
dinocosta merged 3 commits intozed-industries:mainfrom
Ben-Vollrath:fix/multi-select-autoscroll
Mar 27, 2026
Merged

editor: Autoscroll to initial selection on select all matches edit#49232
dinocosta merged 3 commits intozed-industries:mainfrom
Ben-Vollrath:fix/multi-select-autoscroll

Conversation

@Ben-Vollrath
Copy link
Copy Markdown
Contributor

@Ben-Vollrath Ben-Vollrath commented Feb 15, 2026

Closes #32894

Summary

Adjust Select All Matches autoscroll behavior so that when a fit-based strategy can’t keep all selections on screen and we fall back to newest, we scroll to the initial selection that triggered select_all_matches instead of the very last one.

Design decision

The most intuitive behavior is to keep the user oriented around the initial selection:

  • User is still viewing the initial selection → no autoscroll
  • User has scrolled away → autoscroll back to the initial selection (indicate that something happened)

This takes into account the feedback on PR #42009. This implements a fixed version of the first idea.

Implementation details

  • Push the initial selection into new_selections last, so it receives the highest selection id.
  • The newest fallback uses the highest id (see autoscroll.rs), so when fit fails and the logic falls back to newest, it scrolls to the initial selection, not the very last match.

Release Notes:

  • Fixed an issue where editing selections after editor: select all matches would scroll to the last match

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Feb 15, 2026
@maxdeviant maxdeviant changed the title editor: autoscroll to initial selection on select all matches edit editor: Autoscroll to initial selection on select all matches edit Feb 15, 2026
@zed-community-bot zed-community-bot bot added the first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions label Feb 15, 2026
@MrSubidubi MrSubidubi self-assigned this Feb 16, 2026
* Improve the documentation on `Editor::select_all_matches` to make it a
  little bit clearer why we're actually pushing the initial range last.
* Update the existing `test_select_all_matches_does_not_scroll` test in
  order to also verify the case where the selections are not reversed.
Copy link
Copy Markdown
Member

@dinocosta dinocosta left a comment

Choose a reason for hiding this comment

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

Thank you for suggesting this fix @Ben-Vollrath ! 🙂

I've pushed a smaller commit refactoring a small part of the code and update an existing test to actually catch the bug that is being fixed. Shipping! 🚀

@dinocosta dinocosta merged commit a2f1703 into zed-industries:main Mar 27, 2026
32 checks passed
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 first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Select All Matches auto-scrolls to the last occurrence when editing the initial one

3 participants