diff --git a/src/app.rs b/src/app.rs index fd010bca..fc45c551 100644 --- a/src/app.rs +++ b/src/app.rs @@ -410,40 +410,6 @@ impl App { } } - pub fn on_delete(&mut self) { - match self.current_widget_selected { - WidgetPosition::Process => self.start_dd(), - WidgetPosition::ProcessSearch => { - if self.process_search_state.search_state.is_enabled - && self - .process_search_state - .search_state - .current_cursor_position < self - .process_search_state - .search_state - .current_search_query - .len() - { - self.process_search_state - .search_state - .current_search_query - .remove( - self.process_search_state - .search_state - .current_cursor_position, - ); - - self.update_regex(); - self.update_process_gui = true; - } - } - _ => {} - } - } - - /// Deletes an entire word till the next space or end - pub fn on_skip_backspace(&mut self) {} - pub fn is_searching(&self) -> bool { self.process_search_state.search_state.is_enabled } @@ -567,6 +533,65 @@ impl App { } } + pub fn on_delete(&mut self) { + match self.current_widget_selected { + WidgetPosition::Process => self.start_dd(), + WidgetPosition::ProcessSearch => { + if self.process_search_state.search_state.is_enabled + && self + .process_search_state + .search_state + .current_cursor_position < self + .process_search_state + .search_state + .current_search_query + .len() + { + self.process_search_state + .search_state + .current_search_query + .remove( + self.process_search_state + .search_state + .current_cursor_position, + ); + + self.update_regex(); + self.update_process_gui = true; + } + } + _ => {} + } + } + + /// Deletes an entire word till the next space or end + #[allow(unused_variables)] + pub fn on_skip_backspace(&mut self) { + if let WidgetPosition::ProcessSearch = self.current_widget_selected { + if self.process_search_state.search_state.is_enabled { + // Starting from the current position, work backwards on each char until we hit whitespace + let search_chars = self + .process_search_state + .search_state + .current_search_query + .chars(); + } + } + } + + pub fn clear_search(&mut self) { + if let WidgetPosition::ProcessSearch = self.current_widget_selected { + self.process_search_state + .search_state + .current_cursor_position = 0; + self.process_search_state.search_state.current_search_query = String::default(); + self.process_search_state + .search_state + .is_invalid_or_blank_search = true; + self.update_process_gui = true; + } + } + pub fn on_backspace(&mut self) { if let WidgetPosition::ProcessSearch = self.current_widget_selected { if self.process_search_state.search_state.is_enabled diff --git a/src/constants.rs b/src/constants.rs index d4e209a7..09f16fe2 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -12,7 +12,7 @@ pub const DEFAULT_UNIX_CONFIG_FILE_PATH: &str = "~/.config/btm/btm.toml"; pub const DEFAULT_WINDOWS_CONFIG_FILE_PATH: &str = ""; // Help text -pub const GENERAL_HELP_TEXT: [&str; 17] = [ +pub const GENERAL_HELP_TEXT: [&str; 15] = [ "General Keybindings\n\n", "q, Ctrl-c Quit bottom\n", "Esc Close filters, dialog boxes, etc.", @@ -23,8 +23,6 @@ pub const GENERAL_HELP_TEXT: [&str; 17] = [ "H/J/K/L Move currently selected widget up/down/left/right\n", "Up, k Move cursor up\n", "Down, j Move cursor down\n", - "Left, h Move cursor left\n", - "Right, l Move cursor right\n", "? Open the help screen\n", "gg Skip to the first entry of a list\n", "G Skip to the last entry of a list\n", @@ -43,12 +41,17 @@ pub const PROCESS_HELP_TEXT: [&str; 8] = [ "Ctrl-f, / Open up the search widget\n", ]; -pub const SEARCH_HELP_TEXT: [&str; 8] = [ +pub const SEARCH_HELP_TEXT: [&str; 13] = [ "Search Keybindings\n\n", "Tab Toggle between searching for PID and name.\n", "Esc Close search widget\n", "Ctrl-a Skip to the start of search widget\n", "Ctrl-e Skip to the end of search widget\n", + "Ctrl-u Clear the current search query\n", + "Backspace Delete the character behind the cursor\n", + "Delete Delete the character at the cursor\n", + "Left Move cursor left\n", + "Right Move cursor right\n", "Alt-c Toggle whether to ignore case\n", "Alt-m Toggle whether to match the whole word\n", "Alt-r Toggle whether to use regex\n", diff --git a/src/main.rs b/src/main.rs index 426ab268..6c20c0b4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -340,9 +340,10 @@ fn handle_key_event_or_break( app.reset(); } } + KeyCode::Char('u') => app.clear_search(), KeyCode::Char('a') => app.skip_cursor_beginning(), KeyCode::Char('e') => app.skip_cursor_end(), - KeyCode::Backspace => app.on_skip_backspace(), + // TODO: [FEATURE] Ctrl-backspace KeyCode::Backspace => app.on_skip_backspace(), _ => {} } } else if let KeyModifiers::SHIFT = event.modifiers {