Merge 8d9dd2c8de
into 0e575b2809
This commit is contained in:
commit
6499b54f1c
4 changed files with 60 additions and 6 deletions
|
@ -1470,6 +1470,7 @@ impl Editor {
|
|||
}
|
||||
|
||||
pub(crate) enum BufferSearchHighlights {}
|
||||
const ACTIVE_SEARCH_MATCH_KEY: usize = 0;
|
||||
impl SearchableItem for Editor {
|
||||
type Match = Range<Anchor>;
|
||||
|
||||
|
@ -1488,6 +1489,13 @@ impl SearchableItem for Editor {
|
|||
{
|
||||
cx.emit(SearchEvent::MatchesInvalidated);
|
||||
}
|
||||
|
||||
self.highlight_background_key::<BufferSearchHighlights>(
|
||||
ACTIVE_SEARCH_MATCH_KEY,
|
||||
&[],
|
||||
|theme| theme.colors().element_selection_background,
|
||||
cx,
|
||||
);
|
||||
}
|
||||
|
||||
fn update_matches(
|
||||
|
@ -1506,6 +1514,33 @@ impl SearchableItem for Editor {
|
|||
|theme| theme.colors().search_match_background,
|
||||
cx,
|
||||
);
|
||||
|
||||
let active_ix = active_match_index(
|
||||
Direction::Next,
|
||||
matches,
|
||||
&self.selections.newest_anchor().head(),
|
||||
&self.buffer().read(cx).snapshot(cx),
|
||||
);
|
||||
match active_ix {
|
||||
Some(ix) => {
|
||||
let range = &matches[ix];
|
||||
self.highlight_background_key::<BufferSearchHighlights>(
|
||||
ACTIVE_SEARCH_MATCH_KEY,
|
||||
std::slice::from_ref(range),
|
||||
|theme| theme.colors().element_selection_background,
|
||||
cx,
|
||||
);
|
||||
}
|
||||
None => {
|
||||
self.highlight_background_key::<BufferSearchHighlights>(
|
||||
ACTIVE_SEARCH_MATCH_KEY,
|
||||
&[],
|
||||
|theme| theme.colors().element_selection_background,
|
||||
cx,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if updated {
|
||||
cx.emit(SearchEvent::MatchesInvalidated);
|
||||
}
|
||||
|
@ -1603,7 +1638,13 @@ impl SearchableItem for Editor {
|
|||
let range = self.range_for_match(&matches[index]);
|
||||
self.change_selections(Default::default(), window, cx, |s| {
|
||||
s.select_ranges([range]);
|
||||
})
|
||||
});
|
||||
self.highlight_background_key::<BufferSearchHighlights>(
|
||||
ACTIVE_SEARCH_MATCH_KEY,
|
||||
std::slice::from_ref(&matches[index]),
|
||||
|theme| theme.colors().element_selection_background,
|
||||
cx,
|
||||
);
|
||||
}
|
||||
|
||||
fn select_matches(
|
||||
|
|
|
@ -1551,6 +1551,7 @@ mod tests {
|
|||
&[
|
||||
DisplayPoint::new(DisplayRow(2), 17)..DisplayPoint::new(DisplayRow(2), 19),
|
||||
DisplayPoint::new(DisplayRow(2), 43)..DisplayPoint::new(DisplayRow(2), 45),
|
||||
DisplayPoint::new(DisplayRow(2), 17)..DisplayPoint::new(DisplayRow(2), 19),
|
||||
]
|
||||
);
|
||||
});
|
||||
|
@ -1564,7 +1565,10 @@ mod tests {
|
|||
editor.update_in(cx, |editor, window, cx| {
|
||||
assert_eq!(
|
||||
display_points_of(editor.all_text_background_highlights(window, cx)),
|
||||
&[DisplayPoint::new(DisplayRow(2), 43)..DisplayPoint::new(DisplayRow(2), 45),]
|
||||
&[
|
||||
DisplayPoint::new(DisplayRow(2), 43)..DisplayPoint::new(DisplayRow(2), 45),
|
||||
DisplayPoint::new(DisplayRow(2), 43)..DisplayPoint::new(DisplayRow(2), 45),
|
||||
]
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -1587,6 +1591,7 @@ mod tests {
|
|||
DisplayPoint::new(DisplayRow(3), 11)..DisplayPoint::new(DisplayRow(3), 13),
|
||||
DisplayPoint::new(DisplayRow(3), 56)..DisplayPoint::new(DisplayRow(3), 58),
|
||||
DisplayPoint::new(DisplayRow(3), 60)..DisplayPoint::new(DisplayRow(3), 62),
|
||||
DisplayPoint::new(DisplayRow(0), 24)..DisplayPoint::new(DisplayRow(0), 26),
|
||||
]
|
||||
);
|
||||
});
|
||||
|
@ -1604,6 +1609,7 @@ mod tests {
|
|||
DisplayPoint::new(DisplayRow(0), 41)..DisplayPoint::new(DisplayRow(0), 43),
|
||||
DisplayPoint::new(DisplayRow(3), 11)..DisplayPoint::new(DisplayRow(3), 13),
|
||||
DisplayPoint::new(DisplayRow(3), 56)..DisplayPoint::new(DisplayRow(3), 58),
|
||||
DisplayPoint::new(DisplayRow(0), 41)..DisplayPoint::new(DisplayRow(0), 43),
|
||||
]
|
||||
);
|
||||
});
|
||||
|
@ -1823,7 +1829,10 @@ mod tests {
|
|||
editor.update_in(cx, |editor, window, cx| {
|
||||
assert_eq!(
|
||||
display_points_of(editor.all_text_background_highlights(window, cx)),
|
||||
&[DisplayPoint::new(DisplayRow(2), 43)..DisplayPoint::new(DisplayRow(2), 45),]
|
||||
&[
|
||||
DisplayPoint::new(DisplayRow(2), 43)..DisplayPoint::new(DisplayRow(2), 45),
|
||||
DisplayPoint::new(DisplayRow(2), 43)..DisplayPoint::new(DisplayRow(2), 45)
|
||||
]
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -1848,7 +1857,10 @@ mod tests {
|
|||
editor.update_in(cx, |editor, window, cx| {
|
||||
assert_eq!(
|
||||
display_points_of(editor.all_text_background_highlights(window, cx)),
|
||||
&[DisplayPoint::new(DisplayRow(0), 35)..DisplayPoint::new(DisplayRow(0), 40),]
|
||||
&[
|
||||
DisplayPoint::new(DisplayRow(0), 35)..DisplayPoint::new(DisplayRow(0), 40),
|
||||
DisplayPoint::new(DisplayRow(0), 35)..DisplayPoint::new(DisplayRow(0), 40),
|
||||
]
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -2695,6 +2707,7 @@ mod tests {
|
|||
&[
|
||||
DisplayPoint::new(DisplayRow(0), 10)..DisplayPoint::new(DisplayRow(0), 20),
|
||||
DisplayPoint::new(DisplayRow(1), 9)..DisplayPoint::new(DisplayRow(1), 19),
|
||||
DisplayPoint::new(DisplayRow(0), 10)..DisplayPoint::new(DisplayRow(0), 20),
|
||||
],
|
||||
);
|
||||
});
|
||||
|
|
|
@ -752,7 +752,7 @@ mod test {
|
|||
|
||||
cx.update_editor(|editor, window, cx| {
|
||||
let highlights = editor.all_text_background_highlights(window, cx);
|
||||
assert_eq!(3, highlights.len());
|
||||
assert_eq!(4, highlights.len());
|
||||
assert_eq!(
|
||||
DisplayPoint::new(DisplayRow(2), 0)..DisplayPoint::new(DisplayRow(2), 2),
|
||||
highlights[0].0
|
||||
|
|
|
@ -273,7 +273,7 @@ async fn test_selection_on_search(cx: &mut gpui::TestAppContext) {
|
|||
|
||||
cx.update_editor(|editor, window, cx| {
|
||||
let highlights = editor.all_text_background_highlights(window, cx);
|
||||
assert_eq!(3, highlights.len());
|
||||
assert_eq!(4, highlights.len());
|
||||
assert_eq!(
|
||||
DisplayPoint::new(DisplayRow(2), 0)..DisplayPoint::new(DisplayRow(2), 2),
|
||||
highlights[0].0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue