Added in-program hotkey (Ctrl-S) to switch search levels, need to add some GUI indication. Also made it so that you don't need ENTER anymore to search... will monitor and test how this affects performance.

This commit is contained in:
ClementTsang 2020-01-15 22:57:00 -05:00
parent 5d0c8a9f32
commit a4badebd73
2 changed files with 15 additions and 12 deletions

View File

@ -227,6 +227,14 @@ impl App {
&self.current_search_query
}
pub fn toggle_simple_search(&mut self) {
if !self.is_in_dialog() && self.is_searching() {
if let ApplicationPosition::ProcessSearch = self.current_application_position {
self.use_simple = !self.use_simple;
}
}
}
/// One of two functions allowed to run while in a dialog...
pub fn on_enter(&mut self) {
if self.show_dd {
@ -241,18 +249,6 @@ impl App {
self.show_dd = false;
}
}
} else if let ApplicationPosition::ProcessSearch = self.current_application_position {
// Generate regex.
// TODO: [OPT] if we can get this to work WITHOUT pressing enter that would be good.
// However, this will be a bit hard without a thorough look at optimization to avoid
// wasteful regex generation.
self.current_regex = if self.current_search_query.is_empty() {
BASE_REGEX.clone()
} else {
regex::Regex::new(&(self.current_search_query))
};
}
}
@ -280,6 +276,12 @@ impl App {
if let ApplicationPosition::ProcessSearch = self.current_application_position {
self.current_search_query.push(caught_char);
self.current_regex = if self.current_search_query.is_empty() {
BASE_REGEX.clone()
} else {
regex::Regex::new(&(self.current_search_query))
};
} else {
match caught_char {
'/' => {

View File

@ -253,6 +253,7 @@ fn main() -> error::Result<()> {
app.reset();
}
}
KeyCode::Char('s') => app.toggle_simple_search(),
_ => {}
}
}