From 5b7263d5d8ffb87e1792964a7dfe9fb3d6630cbd Mon Sep 17 00:00:00 2001 From: Wojciech Kozlowski Date: Mon, 12 Feb 2024 23:18:03 +0100 Subject: [PATCH] Implement cancel search --- src/tui/app/app.rs | 9 ++++++++- src/tui/handler.rs | 3 +++ src/tui/ui.rs | 9 +++++++-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/tui/app/app.rs b/src/tui/app/app.rs index 8dc5f41..aef8fac 100644 --- a/src/tui/app/app.rs +++ b/src/tui/app/app.rs @@ -111,6 +111,7 @@ pub trait IAppInteractSearch { fn search_next(&mut self); fn step_back(&mut self); fn finish_search(&mut self); + fn cancel_search(&mut self); } pub trait IAppInteractError { @@ -301,7 +302,6 @@ impl IAppInteractReloadPrivate for App { } } -// FIXME: Also add a `cancel_search` which returns to the previous selection. impl IAppInteractSearch for App { fn append_character(&mut self, ch: char) { let collection = self.music_hoard.get_collection(); @@ -339,6 +339,13 @@ impl IAppInteractSearch for App { assert!(self.state.is_search()); self.state = AppState::Browse(()); } + + fn cancel_search(&mut self) { + assert!(self.state.is_search()); + let collection = self.music_hoard.get_collection(); + self.selection.select_artist(collection, self.orig); + self.state = AppState::Browse(()); + } } impl IAppInteractError for App { diff --git a/src/tui/handler.rs b/src/tui/handler.rs index e52e9cb..9ce9411 100644 --- a/src/tui/handler.rs +++ b/src/tui/handler.rs @@ -151,6 +151,9 @@ impl IEventHandlerPrivate for EventHandler { KeyCode::Char('s') | KeyCode::Char('S') => { app.search_next(); }, + KeyCode::Char('g') | KeyCode::Char('G') => { + app.cancel_search(); + }, _ => {} } return; diff --git a/src/tui/ui.rs b/src/tui/ui.rs index 9525cbf..cea31c6 100644 --- a/src/tui/ui.rs +++ b/src/tui/ui.rs @@ -348,6 +348,7 @@ impl<'a, 'b> TrackState<'a, 'b> { struct Minibuffer<'a> { paragraphs: Vec>, + // FIXME: make this an option columns: u16, } @@ -376,8 +377,12 @@ impl Minibuffer<'_> { columns, }, AppState::Search(ref s) => Minibuffer { - paragraphs: vec![Paragraph::new(format!("I-search: {s}"))], - columns: 1, + paragraphs: vec![ + Paragraph::new(format!("I-search: {s}")), + Paragraph::new(format!("ctrl+s: search next")).alignment(Alignment::Center), + Paragraph::new(format!("ctrl+g: cancel search")).alignment(Alignment::Center), + ], + columns, }, AppState::Error(_) => Minibuffer { paragraphs: vec![Paragraph::new(