feat: quit and focus_search keybinds

This commit is contained in:
electria 2026-08-26 12:42:29 -07:00
commit b4ac07ffc4
Signed by: electria
SSH key fingerprint: SHA256:8LlB3ucPbBHqozqkhsNbaV5oG3SlzzqUj8FZDL6IPQs

View file

@ -3,7 +3,7 @@ use std::{borrow::Cow, fs};
use iced::{
Alignment, Color, Length, Subscription, Task, application, clipboard, event,
keyboard::{self, Key, key},
theme, widget,
theme, widget, window,
};
use rfd::{AsyncFileDialog, FileHandle};
@ -35,6 +35,9 @@ enum Message {
FocusNext,
FocusPrevious,
FocusSearch,
Quit,
}
#[derive(Default)]
@ -172,6 +175,9 @@ impl State {
Message::FocusNext => return widget::operation::focus_next(),
Message::FocusPrevious => return widget::operation::focus_previous(),
Message::FocusSearch => return widget::operation::focus("search"),
Message::Quit => return window::latest().and_then(window::close),
}
Task::none()
@ -181,6 +187,7 @@ impl State {
widget::column([
widget::text_input("search query", &self.query)
.on_input(Message::ChangeQuery)
.id("search")
.into(),
widget::scrollable(
widget::grid(self.db_view.iter().enumerate().flat_map(|(i, entry)| {
@ -331,6 +338,7 @@ impl State {
} else {
Message::FocusNext
}),
Key::Character("/") => Some(Message::FocusSearch),
Key::Named(key::Named::Enter) if !db_loaded && db_path_exists => {
Some(Message::OpenDb)
@ -352,6 +360,8 @@ impl State {
Key::Character("y" | "c") if db_loaded => Some(Message::Copy),
Key::Character("q") => Some(Message::Quit),
// ignore unused keys
_ => None,
}