feat: quit and focus_search keybinds
This commit is contained in:
parent
7c86e3d496
commit
b4ac07ffc4
1 changed files with 11 additions and 1 deletions
|
|
@ -3,7 +3,7 @@ use std::{borrow::Cow, fs};
|
||||||
use iced::{
|
use iced::{
|
||||||
Alignment, Color, Length, Subscription, Task, application, clipboard, event,
|
Alignment, Color, Length, Subscription, Task, application, clipboard, event,
|
||||||
keyboard::{self, Key, key},
|
keyboard::{self, Key, key},
|
||||||
theme, widget,
|
theme, widget, window,
|
||||||
};
|
};
|
||||||
use rfd::{AsyncFileDialog, FileHandle};
|
use rfd::{AsyncFileDialog, FileHandle};
|
||||||
|
|
||||||
|
|
@ -35,6 +35,9 @@ enum Message {
|
||||||
|
|
||||||
FocusNext,
|
FocusNext,
|
||||||
FocusPrevious,
|
FocusPrevious,
|
||||||
|
FocusSearch,
|
||||||
|
|
||||||
|
Quit,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
|
@ -172,6 +175,9 @@ impl State {
|
||||||
|
|
||||||
Message::FocusNext => return widget::operation::focus_next(),
|
Message::FocusNext => return widget::operation::focus_next(),
|
||||||
Message::FocusPrevious => return widget::operation::focus_previous(),
|
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()
|
Task::none()
|
||||||
|
|
@ -181,6 +187,7 @@ impl State {
|
||||||
widget::column([
|
widget::column([
|
||||||
widget::text_input("search query", &self.query)
|
widget::text_input("search query", &self.query)
|
||||||
.on_input(Message::ChangeQuery)
|
.on_input(Message::ChangeQuery)
|
||||||
|
.id("search")
|
||||||
.into(),
|
.into(),
|
||||||
widget::scrollable(
|
widget::scrollable(
|
||||||
widget::grid(self.db_view.iter().enumerate().flat_map(|(i, entry)| {
|
widget::grid(self.db_view.iter().enumerate().flat_map(|(i, entry)| {
|
||||||
|
|
@ -331,6 +338,7 @@ impl State {
|
||||||
} else {
|
} else {
|
||||||
Message::FocusNext
|
Message::FocusNext
|
||||||
}),
|
}),
|
||||||
|
Key::Character("/") => Some(Message::FocusSearch),
|
||||||
|
|
||||||
Key::Named(key::Named::Enter) if !db_loaded && db_path_exists => {
|
Key::Named(key::Named::Enter) if !db_loaded && db_path_exists => {
|
||||||
Some(Message::OpenDb)
|
Some(Message::OpenDb)
|
||||||
|
|
@ -352,6 +360,8 @@ impl State {
|
||||||
|
|
||||||
Key::Character("y" | "c") if db_loaded => Some(Message::Copy),
|
Key::Character("y" | "c") if db_loaded => Some(Message::Copy),
|
||||||
|
|
||||||
|
Key::Character("q") => Some(Message::Quit),
|
||||||
|
|
||||||
// ignore unused keys
|
// ignore unused keys
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue