diff --git a/tui/src/filter.rs b/tui/src/filter.rs index e6ff2cc2..984d5d68 100644 --- a/tui/src/filter.rs +++ b/tui/src/filter.rs @@ -1,5 +1,5 @@ use crate::{state::ListEntry, theme::Theme}; -use crossterm::event::{KeyCode, KeyEvent}; +use crossterm::event::{KeyCode, KeyEvent, KeyModifiers}; use ego_tree::NodeId; use linutil_core::Tab; use ratatui::{ @@ -116,21 +116,27 @@ impl Filter { pub fn handle_key(&mut self, event: &KeyEvent) -> SearchAction { //Insert user input into the search bar match event.code { + KeyCode::Char('c') if event.modifiers.contains(KeyModifiers::CONTROL) => { + return self.exit_search() + } KeyCode::Char(c) => self.insert_char(c), KeyCode::Backspace => self.remove_previous(), KeyCode::Delete => self.remove_next(), KeyCode::Left => return self.cursor_left(), KeyCode::Right => return self.cursor_right(), - KeyCode::Esc => { - self.input_position = 0; - self.search_input.clear(); - return SearchAction::Exit; - } KeyCode::Enter => return SearchAction::Exit, + KeyCode::Esc => return self.exit_search(), _ => return SearchAction::None, }; SearchAction::Update } + + fn exit_search(&mut self) -> SearchAction { + self.input_position = 0; + self.search_input.clear(); + SearchAction::Exit + } + fn cursor_left(&mut self) -> SearchAction { self.input_position = self.input_position.saturating_sub(1); SearchAction::None diff --git a/tui/src/state.rs b/tui/src/state.rs index 9ed61771..4e398ee7 100644 --- a/tui/src/state.rs +++ b/tui/src/state.rs @@ -119,7 +119,10 @@ impl AppState { match self.focus { Focus::Search => ( "Search bar", - Box::new([Shortcut::new("Finish search", ["Enter"])]), + Box::new([ + Shortcut::new("Abort search", ["Esc", "CTRL-c"]), + Shortcut::new("Search", ["Enter"]), + ]), ), Focus::List => {