Clear previous search highlights
This commit is contained in:
parent
7c6c06e10f
commit
4092b0226e
@ -59,6 +59,8 @@ pub struct Editor {
|
|||||||
quit_times: u8,
|
quit_times: u8,
|
||||||
search_last_match: i32,
|
search_last_match: i32,
|
||||||
search_direction: i8,
|
search_direction: i8,
|
||||||
|
search_last_line: usize,
|
||||||
|
search_last_hightlight: Vec<Highlight>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Keycode mapping enum
|
/// Keycode mapping enum
|
||||||
@ -111,6 +113,8 @@ impl Default for Editor {
|
|||||||
quit_times: KILO_QUIT_TIMES,
|
quit_times: KILO_QUIT_TIMES,
|
||||||
search_last_match: -1,
|
search_last_match: -1,
|
||||||
search_direction: 1,
|
search_direction: 1,
|
||||||
|
search_last_line: 0,
|
||||||
|
search_last_hightlight: vec![],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -970,6 +974,11 @@ impl Editor {
|
|||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
|
||||||
fn find_callback(&mut self, query: &str, key: EditorKey<char>) {
|
fn find_callback(&mut self, query: &str, key: EditorKey<char>) {
|
||||||
|
if !self.search_last_hightlight.is_empty() {
|
||||||
|
self.rows[self.search_last_line].highlight = self.search_last_hightlight.clone();
|
||||||
|
self.search_last_hightlight.clear();
|
||||||
|
}
|
||||||
|
|
||||||
if key == Enter || key == Escape {
|
if key == Enter || key == Escape {
|
||||||
self.search_last_match = -1;
|
self.search_last_match = -1;
|
||||||
self.search_direction = 1;
|
self.search_direction = 1;
|
||||||
@ -1009,6 +1018,9 @@ impl Editor {
|
|||||||
self.cursor_x = self.row_rx_to_cx(x, start);
|
self.cursor_x = self.row_rx_to_cx(x, start);
|
||||||
self.row_offset = self.rows.len();
|
self.row_offset = self.rows.len();
|
||||||
|
|
||||||
|
self.search_last_line = current as usize;
|
||||||
|
self.search_last_hightlight = self.rows[current as usize].highlight.clone();
|
||||||
|
|
||||||
// Highlight matching search result
|
// Highlight matching search result
|
||||||
let len = start + query.len();
|
let len = start + query.len();
|
||||||
for x in start..len {
|
for x in start..len {
|
||||||
|
Loading…
Reference in New Issue
Block a user