From 810822b5cd811363dd40ec16609c8cfc7aeec95e Mon Sep 17 00:00:00 2001 From: Steven Date: Mon, 6 Apr 2026 09:46:00 -0700 Subject: [PATCH] Use multibuffer to fix symbol search when diff is present (#52268) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Context Fixes a bug where project symbol search navigates to the wrong position when diff hunks are expanded. The cursor would land offset by the number of lines added by the expanded diffs (Closes #51331). Now, users navigating to symbols via project symbol search will land on the correct position even when diff hunks are expanded in the editor. The fix converts the buffer position to a `multi_buffer::Anchor` before passing it to `select_ranges`, so it resolves correctly through the diff transform layer instead of being interpreted as a literal MultiBuffer coordinate. Previously, the symbol's position was passed as a raw coordinate to the editor, which interpreted it relative to what's displayed on screen (including expanded diff lines). The fix converts the position to an anchor, which is tied to the actual content in the file rather than a screen position. ## How to Review - All changes are in `crates/project_symbols/src/project_symbols.rs`. Most of the changes are in `confirm()` method (Lines 142-154). - There's also one change on the first line of the file. ## Self-Review Checklist - [x] I've reviewed my own diff for quality, security, and reliability - [ ] Unsafe blocks (if any) have justifying comments - [x] The content is consistent with the [UI/UX checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) - [x] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable Release Notes: - Fixed a bug where project symbols did not take you to the correct location when diffs are expanded. --- crates/project_symbols/src/project_symbols.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/crates/project_symbols/src/project_symbols.rs b/crates/project_symbols/src/project_symbols.rs index 84b92f3eaa4f0216b881526b3aac42f8980ffe78..351b6e7afb59ef9b7ffd545d36b0e3dd66c6e834 100644 --- a/crates/project_symbols/src/project_symbols.rs +++ b/crates/project_symbols/src/project_symbols.rs @@ -1,4 +1,6 @@ -use editor::{Bias, Editor, SelectionEffects, scroll::Autoscroll, styled_runs_for_code_label}; +use editor::{ + Anchor, Bias, Editor, SelectionEffects, scroll::Autoscroll, styled_runs_for_code_label, +}; use fuzzy::{StringMatch, StringMatchCandidate}; use gpui::{ App, Context, DismissEvent, Entity, HighlightStyle, ParentElement, StyledText, Task, TextStyle, @@ -140,11 +142,19 @@ impl PickerDelegate for ProjectSymbolsDelegate { ); editor.update(cx, |editor, cx| { + let multibuffer_snapshot = editor.buffer().read(cx).snapshot(cx); + let Some((excerpt_id, _, buffer_snapshot)) = + multibuffer_snapshot.as_singleton() + else { + return; + }; + let text_anchor = buffer_snapshot.anchor_before(position); + let anchor = Anchor::in_buffer(excerpt_id, text_anchor); editor.change_selections( SelectionEffects::scroll(Autoscroll::center()), window, cx, - |s| s.select_ranges([position..position]), + |s| s.select_ranges([anchor..anchor]), ); }); })?;