🔍️ exiting search with Ctrl-C + better shortcut tips (#768)

This commit is contained in:
Adam Perkowski 2024-10-24 21:43:16 +02:00 committed by GitHub
parent fa2f838b63
commit 4f7de594a6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 7 deletions

View File

@ -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

View File

@ -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 => {