From 96a5cc63cce9a2a8f505538268a42fef0891f0b5 Mon Sep 17 00:00:00 2001 From: lukeflo Date: Sat, 28 Sep 2024 23:11:15 +0200 Subject: start impl of search mode --- src/frontend/handler.rs | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) (limited to 'src/frontend/handler.rs') diff --git a/src/frontend/handler.rs b/src/frontend/handler.rs index 73f30ae..27aa8de 100644 --- a/src/frontend/handler.rs +++ b/src/frontend/handler.rs @@ -18,7 +18,7 @@ use crate::frontend::app::{App, AppResult}; use crossterm::event::{KeyCode, KeyEvent, KeyModifiers}; -use super::app::CurrentArea; +use super::app::{CurrentArea, FormerArea}; /// Handles the key events and updates the state of [`App`]. pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> { @@ -61,6 +61,10 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> { KeyCode::Char('G') | KeyCode::End => { app.select_last(); } + KeyCode::Char('/') => { + app.former_area = Some(FormerArea::TagArea); + app.current_area = CurrentArea::SearchArea; + } KeyCode::Tab | KeyCode::BackTab => { app.toggle_area(); } @@ -86,11 +90,47 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> { KeyCode::Char('y') => { App::yank_text(&app.get_selected_citekey()); } + KeyCode::Char('/') => { + app.former_area = Some(FormerArea::EntryArea); + app.current_area = CurrentArea::SearchArea; + } KeyCode::Tab | KeyCode::BackTab => { app.toggle_area(); } _ => {} }, + // Keycodes for the search area (popup) + CurrentArea::SearchArea => match key_event.code { + KeyCode::Esc => { + app.toggle_area(); + app.former_area = None; + app.search_string.clear(); + } + KeyCode::Enter => { + // TODO: run function for filtering the list + app.toggle_area(); + app.former_area = None; + app.search_string.clear(); + } + KeyCode::Backspace => { + app.search_string.pop(); + } + KeyCode::Char(search_pattern) => { + app.search_string.push(search_pattern); + } + _ => {} + }, + // Keycodes for the help area (popup) + CurrentArea::HelpArea => match key_event.code { + KeyCode::Char('q') => { + app.quit(); + } + KeyCode::Esc => { + app.toggle_area(); + app.former_area = None; + } + _ => {} + }, } Ok(()) } -- cgit v1.2.3