From 9298d3b525abdb1eb67acaaf4c2395451c747fcb Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Sun, 23 Jun 2024 18:53:27 +0200 Subject: [PATCH] editor: Select first match in "Find all references" editor (#13424) Previously we've placed cursor on the first line of the first excerpt in the multibuffer, but alas, https://x.com/fasterthanlime/status/1804883499809165473 happened (j/k, this feedback is totally valid) and now we're gonna place it at the end of the first reference. As a bonus, with the old configuration `editor: select next` tripped over itself. Now it's possible (& feasible) to do a "select next" in "find all references"; consecutive referenced ranges will be selected. Fixes #13419 Release Notes: - Fixed a bug where "Find all references" editor had cursor placed on the first line of the first excerpt in the multibuffer instead of having it on the first reference. --- crates/editor/src/editor.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 4477fa8bbd9170edbe3df3c38e8386e89f54c316..fc82b3f30e8dfadfeaf47deb26eb5c4a90fcbe35 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -9181,6 +9181,12 @@ impl Editor { Editor::for_multibuffer(excerpt_buffer, Some(workspace.project().clone()), true, cx) }); editor.update(cx, |editor, cx| { + if let Some(first_range) = ranges_to_highlight.first() { + editor.change_selections(None, cx, |selections| { + selections.clear_disjoint(); + selections.select_anchor_ranges(std::iter::once(first_range.clone())); + }); + } editor.highlight_background::( &ranges_to_highlight, |theme| theme.editor_highlighted_line_background,