add type-to-select option for keyboard navigation

This commit is contained in:
wowitsjack 2025-12-27 19:07:21 +10:00
parent d9b6404f1b
commit 5e92d081c6
5 changed files with 71 additions and 0 deletions

View file

@ -733,6 +733,8 @@ pub struct App {
windows: FxHashMap<window::Id, Window>,
nav_dnd_hover: Option<(Location, Instant)>,
tab_dnd_hover: Option<(Entity, Instant)>,
type_select_prefix: String,
type_select_last_key: Option<Instant>,
nav_drag_id: DragId,
tab_drag_id: DragId,
auto_scroll_speed: Option<i16>,
@ -1985,6 +1987,12 @@ impl App {
Some(self.config.type_to_search),
Message::SetTypeToSearch,
))
.add(widget::radio(
widget::text::body(fl!("type-to-search-select")),
TypeToSearch::SelectByPrefix,
Some(self.config.type_to_search),
Message::SetTypeToSearch,
))
.into(),
widget::settings::section()
.title(fl!("other"))
@ -2213,6 +2221,8 @@ impl Application for App {
windows: FxHashMap::default(),
nav_dnd_hover: None,
tab_dnd_hover: None,
type_select_prefix: String::new(),
type_select_last_key: None,
nav_drag_id: DragId::new(),
tab_drag_id: DragId::new(),
auto_scroll_speed: None,
@ -3039,6 +3049,22 @@ impl Application for App {
}
}
}
TypeToSearch::SelectByPrefix => {
// Reset buffer if timeout elapsed
if let Some(last_key) = self.type_select_last_key {
if last_key.elapsed() >= tab::TYPE_SELECT_TIMEOUT {
self.type_select_prefix.clear();
}
}
// Accumulate character and select
self.type_select_prefix.push_str(&text.to_lowercase());
self.type_select_last_key = Some(Instant::now());
if let Some(tab) = self.tab_model.data_mut::<Tab>(entity) {
tab.select_by_prefix(&self.type_select_prefix);
}
}
}
}
}