Implement cancel search

This commit is contained in:
Wojciech Kozlowski 2024-02-12 23:18:03 +01:00
parent a29a3fa3ce
commit 5b7263d5d8
3 changed files with 18 additions and 3 deletions

View File

@ -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<MH: IMusicHoard> IAppInteractReloadPrivate for App<MH> {
}
}
// FIXME: Also add a `cancel_search` which returns to the previous selection.
impl<MH: IMusicHoard> IAppInteractSearch for App<MH> {
fn append_character(&mut self, ch: char) {
let collection = self.music_hoard.get_collection();
@ -339,6 +339,13 @@ impl<MH: IMusicHoard> IAppInteractSearch for App<MH> {
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<MH: IMusicHoard> IAppInteractError for App<MH> {

View File

@ -151,6 +151,9 @@ impl<APP: IAppInteract> IEventHandlerPrivate<APP> for EventHandler {
KeyCode::Char('s') | KeyCode::Char('S') => {
app.search_next();
},
KeyCode::Char('g') | KeyCode::Char('G') => {
app.cancel_search();
},
_ => {}
}
return;

View File

@ -348,6 +348,7 @@ impl<'a, 'b> TrackState<'a, 'b> {
struct Minibuffer<'a> {
paragraphs: Vec<Paragraph<'a>>,
// 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(