fix: highlight all search matches before word navigation

This commit is contained in:
Valdemar Lorenzen
2026-10-15 12:12:05 +02:00
parent 7b3b3866fd
commit de62467208
4 changed files with 176 additions and 33 deletions
+68 -1
View File
@@ -3122,7 +3122,7 @@ fn paint_editor_line(
paint_grapheme_range(frame, area, left, line, start..end, style);
}
}
if let Some(found) = editor.search_match().filter(|found| found.start.row == row) {
for found in editor.search_matches_on_row(row) {
paint_cells(
frame,
area,
@@ -18877,6 +18877,73 @@ end
assert_ne!(buffer[(6, 0)].bg, Color::Blue);
}
#[test]
fn search_highlights_all_occurrences_without_moving_on_first_star() {
let mut editor = Editor::open(None, vec![]).unwrap();
editor.set_gutter_style(crate::gutter::GutterStyle::None);
configure_chrome(&mut editor, |top, bottom| {
for bar in [top, bottom] {
bar.left.clear();
bar.center.clear();
bar.right.clear();
}
});
editor
.apply(vec![crate::editor::Effect::Replace(
"cat cat_cat cat\ncat".into(),
)])
.unwrap();
editor.handle(Input::Char('*'));
assert_eq!(editor.cursor(), Cursor::default());
let mut terminal = Terminal::new(ratatui::backend::TestBackend::new(30, 6)).unwrap();
let (mut top, mut left) = (0, 0);
let mut syntax = SyntaxCache::new();
terminal
.draw(|frame| {
draw(
frame,
&editor,
&mut top,
&mut left,
&mut syntax,
&mut DocumentViewport::default(),
&mut WheelPanels::default(),
);
})
.unwrap();
let buffer = terminal.backend().buffer();
for (row, start, end) in [(0, 0, 3), (0, 12, 15), (1, 0, 3)] {
for column in start..end {
assert_eq!(buffer[(column + 2, row)].bg, Color::Yellow);
}
}
assert_ne!(buffer[(6, 0)].bg, Color::Yellow);
editor.handle(Input::Char('/'));
for ch in "cat".chars() {
editor.handle(Input::Char(ch));
}
editor.handle(Input::Enter);
terminal
.draw(|frame| {
draw(
frame,
&editor,
&mut top,
&mut left,
&mut syntax,
&mut DocumentViewport::default(),
&mut WheelPanels::default(),
);
})
.unwrap();
for column in [0, 4, 8, 12] {
assert_eq!(
terminal.backend().buffer()[(column + 2, 0)].bg,
Color::Yellow
);
}
}
#[test]
fn active_search_highlight_uses_display_cells_and_clips_with_horizontal_scroll() {
let mut editor = Editor::open(None, vec![]).unwrap();