From 7aafbe2207428d10cba85636fff2ba224c8e08e2 Mon Sep 17 00:00:00 2001 From: electria Date: Thu, 27 Aug 2026 10:28:49 -0700 Subject: [PATCH] feat: more selection keybinds also deduplicates code into State::populate_view --- src/app/mod.rs | 48 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/src/app/mod.rs b/src/app/mod.rs index 447be4c..d08935a 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -29,6 +29,9 @@ enum Message { SelectionUp, SelectionRight, + SelectionTop, + SelectionBottom, + ChangeQuery(String), Copy, @@ -108,11 +111,8 @@ impl State { match result { Ok(db) => { self.error = "".into(); - self.db_view = db - .iter_all_entries() - .map(|entry_ref| entry_ref.clone()) - .collect(); self.db = Some(db); + self.populate_view(); self.db_loaded = true; } Err(e) => self.error = e.into(), @@ -140,19 +140,12 @@ impl State { } Message::SelectionRight => self.selected_field.next(), + Message::SelectionTop => self.selected_entry = 0, + Message::SelectionBottom => self.selected_entry = self.db_view.len() - 1, + Message::ChangeQuery(str) => { self.query = str; - self.db_view = self - .db - .as_ref() - .unwrap() - .iter_all_entries() - .filter_map(|entry_ref| { - entry_ref - .contains(&self.query) - .then(|| entry_ref.to_owned()) - }) - .collect(); + self.populate_view(); } Message::Copy => { @@ -358,6 +351,14 @@ impl State { Some(Message::SelectionRight) } + Key::Character("g") => Some(if modifiers.shift() { + Message::SelectionBottom + } else { + Message::SelectionTop + }), + Key::Named(key::Named::Home) => Some(Message::SelectionTop), + Key::Named(key::Named::End) => Some(Message::SelectionBottom), + Key::Character("y" | "c") if db_loaded => Some(Message::Copy), Key::Character("q") => Some(Message::Quit), @@ -393,6 +394,23 @@ impl State { Message::DbOpened, ) } + + fn populate_view(&mut self) { + self.db_view = self + .db + .as_ref() + .unwrap() + .iter_all_entries() + .filter_map(|entry_ref| { + // this matches everything when the query is an empty string, + // which is the desired behavior so that it displays everything + // (when search isn't being used) + entry_ref + .contains(&self.query) + .then(|| entry_ref.to_owned()) + }) + .collect(); + } } pub fn run() -> Result<(), iced::Error> {