feat: more selection keybinds
also deduplicates code into State::populate_view
This commit is contained in:
parent
b4ac07ffc4
commit
7aafbe2207
1 changed files with 33 additions and 15 deletions
|
|
@ -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> {
|
||||
|
|
|
|||
Loading…
Reference in a new issue