diff options
Diffstat (limited to 'default-plugins/strider/src/state.rs')
-rw-r--r-- | default-plugins/strider/src/state.rs | 80 |
1 files changed, 10 insertions, 70 deletions
diff --git a/default-plugins/strider/src/state.rs b/default-plugins/strider/src/state.rs index 7ced4932c..8dd09653a 100644 --- a/default-plugins/strider/src/state.rs +++ b/default-plugins/strider/src/state.rs @@ -1,4 +1,6 @@ -use crate::search::SearchResult; +use crate::search::search_results::SearchResult; +use crate::search::search_state::SearchState; +use crate::search::search_state::SearchType; use pretty_bytes::converter as pb; use std::{ collections::{HashMap, VecDeque}, @@ -18,65 +20,29 @@ pub struct State { pub cursor_hist: HashMap<PathBuf, (usize, usize)>, pub hide_hidden_files: bool, pub ev_history: VecDeque<(Event, Instant)>, // stores last event, can be expanded in future + pub search_state: SearchState, pub search_paths: Vec<String>, pub search_term: Option<String>, - pub search_results: Vec<SearchResult>, + pub file_name_search_results: Vec<SearchResult>, + pub file_contents_search_results: Vec<SearchResult>, pub loading: bool, pub loading_animation_offset: u8, pub typing_search_term: bool, - pub exploring_search_results: bool, pub selected_search_result: usize, + pub processed_search_index: usize, + pub should_open_floating: bool, + pub search_filter: SearchType, } impl State { - pub fn append_to_search_term(&mut self, key: Key) { - match key { - Key::Char(character) => { - if let Some(search_term) = self.search_term.as_mut() { - search_term.push(character); - } - }, - Key::Backspace => { - if let Some(search_term) = self.search_term.as_mut() { - search_term.pop(); - if search_term.len() == 0 { - self.search_term = None; - self.typing_search_term = false; - } - } - }, - _ => {}, - } - } - pub fn accept_search_term(&mut self) { - self.typing_search_term = false; - self.exploring_search_results = true; - } pub fn typing_search_term(&self) -> bool { self.typing_search_term } - pub fn exploring_search_results(&self) -> bool { - self.exploring_search_results - } - pub fn stop_exploring_search_results(&mut self) { - self.exploring_search_results = false; - } pub fn start_typing_search_term(&mut self) { - if self.search_term.is_none() { - self.search_term = Some(String::new()); - } self.typing_search_term = true; } pub fn stop_typing_search_term(&mut self) { - self.typing_search_term = true; - } - pub fn move_search_selection_up(&mut self) { - self.selected_search_result = self.selected_search_result.saturating_sub(1); - } - pub fn move_search_selection_down(&mut self) { - if self.selected_search_result < self.search_results.len() { - self.selected_search_result = self.selected_search_result.saturating_add(1); - } + self.typing_search_term = false; } pub fn selected_mut(&mut self) -> &mut usize { &mut self.cursor_hist.entry(self.path.clone()).or_default().0 @@ -104,32 +70,6 @@ impl State { } } } - pub fn open_search_result(&mut self) { - match self.search_results.get(self.selected_search_result) { - Some(SearchResult::File { - path, - score, - indices, - }) => { - let file_path = PathBuf::from(path); - open_file(file_path.strip_prefix(ROOT).unwrap()); - }, - Some(SearchResult::LineInFile { - path, - score, - indices, - line, - line_number, - }) => { - let file_path = PathBuf::from(path); - open_file_with_line(file_path.strip_prefix(ROOT).unwrap(), *line_number); - // open_file_with_line(&file_path, *line_number); // TODO: no!! - }, - None => { - eprintln!("Search result not found"); - }, - } - } } #[derive(PartialEq, Eq, PartialOrd, Ord, Clone)] |