Make autoscroll optional when highlighting editor rows (#11950)

Previously, when highlighting editor rows with a color, we always
auto-scrolled to the first highlighted row. This was useful in contexts
like go-to-line and the outline view. We had an explicit special case
for git diff highlights. Now, part of the `highlight_rows` API, you
specify whether or not you want the autoscroll behavior. This is needed
because we want to highlight rows in the assistant panel, and we don't
want the autoscroll.

Release Notes:

- N/A
This commit is contained in:
Max Brunsfeld 2024-05-16 20:28:17 -07:00 committed by GitHub
parent 57b5bff299
commit 4ca6e0e387
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 86 additions and 95 deletions

View file

@ -13,7 +13,6 @@ path = "src/outline.rs"
doctest = false
[dependencies]
collections.workspace = true
editor.workspace = true
fuzzy.workspace = true
gpui.workspace = true

View file

@ -144,6 +144,7 @@ impl OutlineViewDelegate {
active_editor.highlight_rows::<OutlineRowHighlights>(
outline_item.range.start..=outline_item.range.end,
Some(cx.theme().colors().editor_highlighted_line_background),
true,
cx,
);
active_editor.request_autoscroll(Autoscroll::center(), cx);
@ -316,7 +317,7 @@ impl PickerDelegate for OutlineViewDelegate {
#[cfg(test)]
mod tests {
use collections::HashSet;
use super::*;
use gpui::{TestAppContext, VisualTestContext};
use indoc::indoc;
use language::{Language, LanguageConfig, LanguageMatcher};
@ -324,8 +325,6 @@ mod tests {
use serde_json::json;
use workspace::{AppState, Workspace};
use super::*;
#[gpui::test]
async fn test_outline_view_row_highlights(cx: &mut TestAppContext) {
init_test(cx);
@ -484,7 +483,7 @@ mod tests {
fn highlighted_display_rows(editor: &View<Editor>, cx: &mut VisualTestContext) -> Vec<u32> {
editor.update(cx, |editor, cx| {
editor
.highlighted_display_rows(HashSet::default(), cx)
.highlighted_display_rows(cx)
.into_keys()
.map(|r| r.0)
.collect()