Improve context expansion (#10957)

Release Notes:

- Improved expand excerpt indicators to allow unidirectional expansion.
Also added the `editor::ExpandExcerptsUp` and
`editor::ExpandExcerptsDown` actions, which can both take a `lines`
parameter. Also added a `expand_excerpt_lines` setting which controls
the default number of lines that the indicators and actions use.

---------

Co-authored-by: conrad <conrad@zed.dev>
This commit is contained in:
Mikayla Maki
2024-05-26 16:30:09 -07:00
committed by GitHub
co-authored by conrad
parent a0f91299dd
commit a9e3d4ec4e
27 changed files with 904 additions and 328 deletions
+17 -17
View File
@@ -653,7 +653,7 @@ impl ProjectSearchView {
editor
});
let results_editor = cx.new_view(|cx| {
let mut editor = Editor::for_multibuffer(excerpts, Some(project.clone()), cx);
let mut editor = Editor::for_multibuffer(excerpts, Some(project.clone()), true, cx);
editor.set_searchable(false);
editor
});
@@ -1722,7 +1722,7 @@ pub mod tests {
search_view
.results_editor
.update(cx, |editor, cx| editor.display_text(cx)),
"\n\nconst THREE: usize = one::ONE + two::TWO;\n\n\nconst TWO: usize = one::ONE + one::ONE;"
"\n\n\nconst THREE: usize = one::ONE + two::TWO;\n\n\n\n\nconst TWO: usize = one::ONE + one::ONE;\n"
);
let match_background_color = cx.theme().colors().search_match_background;
assert_eq!(
@@ -1731,15 +1731,15 @@ pub mod tests {
.update(cx, |editor, cx| editor.all_text_background_highlights(cx)),
&[
(
DisplayPoint::new(DisplayRow(2), 32)..DisplayPoint::new(DisplayRow(2), 35),
DisplayPoint::new(DisplayRow(3), 32)..DisplayPoint::new(DisplayRow(3), 35),
match_background_color
),
(
DisplayPoint::new(DisplayRow(2), 37)..DisplayPoint::new(DisplayRow(2), 40),
DisplayPoint::new(DisplayRow(3), 37)..DisplayPoint::new(DisplayRow(3), 40),
match_background_color
),
(
DisplayPoint::new(DisplayRow(5), 6)..DisplayPoint::new(DisplayRow(5), 9),
DisplayPoint::new(DisplayRow(8), 6)..DisplayPoint::new(DisplayRow(8), 9),
match_background_color
)
]
@@ -1749,7 +1749,7 @@ pub mod tests {
search_view
.results_editor
.update(cx, |editor, cx| editor.selections.display_ranges(cx)),
[DisplayPoint::new(DisplayRow(2), 32)..DisplayPoint::new(DisplayRow(2), 35)]
[DisplayPoint::new(DisplayRow(3), 32)..DisplayPoint::new(DisplayRow(3), 35)]
);
search_view.select_match(Direction::Next, cx);
@@ -1762,7 +1762,7 @@ pub mod tests {
search_view
.results_editor
.update(cx, |editor, cx| editor.selections.display_ranges(cx)),
[DisplayPoint::new(DisplayRow(2), 37)..DisplayPoint::new(DisplayRow(2), 40)]
[DisplayPoint::new(DisplayRow(3), 37)..DisplayPoint::new(DisplayRow(3), 40)]
);
search_view.select_match(Direction::Next, cx);
})
@@ -1775,7 +1775,7 @@ pub mod tests {
search_view
.results_editor
.update(cx, |editor, cx| editor.selections.display_ranges(cx)),
[DisplayPoint::new(DisplayRow(5), 6)..DisplayPoint::new(DisplayRow(5), 9)]
[DisplayPoint::new(DisplayRow(8), 6)..DisplayPoint::new(DisplayRow(8), 9)]
);
search_view.select_match(Direction::Next, cx);
})
@@ -1788,7 +1788,7 @@ pub mod tests {
search_view
.results_editor
.update(cx, |editor, cx| editor.selections.display_ranges(cx)),
[DisplayPoint::new(DisplayRow(2), 32)..DisplayPoint::new(DisplayRow(2), 35)]
[DisplayPoint::new(DisplayRow(3), 32)..DisplayPoint::new(DisplayRow(3), 35)]
);
search_view.select_match(Direction::Prev, cx);
})
@@ -1801,7 +1801,7 @@ pub mod tests {
search_view
.results_editor
.update(cx, |editor, cx| editor.selections.display_ranges(cx)),
[DisplayPoint::new(DisplayRow(5), 6)..DisplayPoint::new(DisplayRow(5), 9)]
[DisplayPoint::new(DisplayRow(8), 6)..DisplayPoint::new(DisplayRow(8), 9)]
);
search_view.select_match(Direction::Prev, cx);
})
@@ -1814,7 +1814,7 @@ pub mod tests {
search_view
.results_editor
.update(cx, |editor, cx| editor.selections.display_ranges(cx)),
[DisplayPoint::new(DisplayRow(2), 37)..DisplayPoint::new(DisplayRow(2), 40)]
[DisplayPoint::new(DisplayRow(3), 37)..DisplayPoint::new(DisplayRow(3), 40)]
);
})
.unwrap();
@@ -1982,7 +1982,7 @@ pub mod tests {
search_view
.results_editor
.update(cx, |editor, cx| editor.display_text(cx)),
"\n\nconst THREE: usize = one::ONE + two::TWO;\n\n\nconst TWO: usize = one::ONE + one::ONE;",
"\n\n\nconst THREE: usize = one::ONE + two::TWO;\n\n\n\n\nconst TWO: usize = one::ONE + one::ONE;\n",
"Search view results should match the query"
);
assert!(
@@ -2021,7 +2021,7 @@ pub mod tests {
search_view
.results_editor
.update(cx, |editor, cx| editor.display_text(cx)),
"\n\nconst THREE: usize = one::ONE + two::TWO;\n\n\nconst TWO: usize = one::ONE + one::ONE;",
"\n\n\nconst THREE: usize = one::ONE + two::TWO;\n\n\n\n\nconst TWO: usize = one::ONE + one::ONE;\n",
"Results should be unchanged after search view 2nd open in a row"
);
assert!(
@@ -2213,7 +2213,7 @@ pub mod tests {
search_view
.results_editor
.update(cx, |editor, cx| editor.display_text(cx)),
"\n\nconst THREE: usize = one::ONE + two::TWO;\n\n\nconst TWO: usize = one::ONE + one::ONE;",
"\n\n\nconst THREE: usize = one::ONE + two::TWO;\n\n\n\n\nconst TWO: usize = one::ONE + one::ONE;\n",
"Search view results should match the query"
);
assert!(
@@ -2268,7 +2268,7 @@ pub mod tests {
search_view
.results_editor
.update(cx, |editor, cx| editor.display_text(cx)),
"\n\nconst THREE: usize = one::ONE + two::TWO;\n\n\nconst TWO: usize = one::ONE + one::ONE;",
"\n\n\nconst THREE: usize = one::ONE + two::TWO;\n\n\n\n\nconst TWO: usize = one::ONE + one::ONE;\n",
"Results of the first search view should not update too"
);
assert!(
@@ -2317,7 +2317,7 @@ pub mod tests {
search_view_2
.results_editor
.update(cx, |editor, cx| editor.display_text(cx)),
"\n\nconst FOUR: usize = one::ONE + three::THREE;",
"\n\n\nconst FOUR: usize = one::ONE + three::THREE;\n",
"New search view with the updated query should have new search results"
);
assert!(
@@ -2462,7 +2462,7 @@ pub mod tests {
search_view
.results_editor
.update(cx, |editor, cx| editor.display_text(cx)),
"\n\nconst ONE: usize = 1;\n\n\nconst TWO: usize = one::ONE + one::ONE;",
"\n\n\nconst ONE: usize = 1;\n\n\n\n\nconst TWO: usize = one::ONE + one::ONE;\n",
"New search in directory should have a filter that matches a certain directory"
);
})