chore: define search_down keybind at config.rs

This commit is contained in:
ynqa
2025-03-25 02:42:00 +09:00
parent 5508a55252
commit db651c851c
3 changed files with 13 additions and 14 deletions

View File

@@ -13,7 +13,7 @@ use content_style::content_style_serde;
mod duration;
use duration::duration_serde;
pub mod event;
use event::{EventDefSet, KeyEventDef};
use event::{EventDef, EventDefSet, KeyEventDef};
mod text_editor;
use text_editor::text_editor_mode_serde;
@@ -157,6 +157,7 @@ pub struct Keybinds {
pub erase_to_previous_nearest: EventDefSet,
pub erase_to_next_nearest: EventDefSet,
pub search_up: EventDefSet,
pub search_down: EventDefSet,
}
impl Default for Keybinds {
@@ -195,6 +196,10 @@ impl Default for Keybinds {
KeyModifiers::ALT,
)),
search_up: EventDefSet::from(KeyEventDef::new(KeyCode::Up, KeyModifiers::NONE)),
search_down: EventDefSet::from_iter([
EventDef::Key(KeyEventDef::new(KeyCode::Tab, KeyModifiers::NONE)),
EventDef::Key(KeyEventDef::new(KeyCode::Down, KeyModifiers::NONE)),
]),
}
}
}

View File

@@ -16,6 +16,12 @@ impl Matcher<Event> for EventDefSet {
}
}
impl FromIterator<EventDef> for EventDefSet {
fn from_iter<I: IntoIterator<Item = EventDef>>(iter: I) -> Self {
EventDefSet(iter.into_iter().collect())
}
}
impl From<KeyEventDef> for EventDefSet {
fn from(key_event_def: KeyEventDef) -> Self {
EventDefSet(HashSet::from_iter([EventDef::Key(key_event_def)]))

View File

@@ -208,19 +208,7 @@ pub async fn edit<'a>(event: &'a Event, editor: &'a mut Editor) -> anyhow::Resul
pub async fn search<'a>(event: &'a Event, editor: &'a mut Editor) -> anyhow::Result<()> {
match event {
// TODO: Implement the search down keybinds as a collection
Event::Key(KeyEvent {
code: KeyCode::Tab,
modifiers: KeyModifiers::NONE,
kind: KeyEventKind::Press,
state: KeyEventState::NONE,
})
| Event::Key(KeyEvent {
code: KeyCode::Down,
modifiers: KeyModifiers::NONE,
kind: KeyEventKind::Press,
state: KeyEventState::NONE,
}) => {
key if editor.keybinds.search_down.matches(key) => {
editor.searcher.down_with_load();
editor
.state