support auto selection without enter, fixes #83

This commit is contained in:
Alexander Mohr 2025-06-29 13:46:37 +02:00
parent f68ffd88d4
commit 75fc04d8b5
2 changed files with 28 additions and 4 deletions

View file

@ -632,6 +632,10 @@ pub struct Config {
/// Allow submitting selected entry with expand key if there is only 1 item left.
#[clap(long = "submit-with-expand")]
submit_with_expand: Option<bool>,
/// Auto select when only 1 possible choice is left
#[clap(long = "auto-select-on-search")]
auto_select_on_search: Option<bool>,
}
impl Config {
@ -916,6 +920,11 @@ impl Config {
pub fn submit_with_expand(&self) -> bool {
self.submit_with_expand.unwrap_or(true)
}
#[must_use]
pub fn auto_select_on_search(&self) -> bool {
self.auto_select_on_search.unwrap_or(false)
}
}
fn default_false() -> bool {

View file

@ -1175,16 +1175,31 @@ fn update_view<T>(ui: &Rc<UiElements<T>>, meta: &Rc<MetaData<T>>, query: &str)
where
T: Clone + Send + 'static,
{
let mut lock = ui.menu_rows.write().unwrap();
let mut menu_rows = ui.menu_rows.write().unwrap();
set_menu_visibility_for_search(
query,
&mut lock,
&mut menu_rows,
&meta.config,
meta.search_ignored_words.as_ref(),
);
select_first_visible_child(&*lock, &ui.main_box);
drop(lock);
select_first_visible_child(&*menu_rows, &ui.main_box);
if meta.config.read().unwrap().auto_select_on_search() {
let visible_items = menu_rows
.iter()
.filter(|(_, menu)| menu.visible)
.collect::<Vec<_>>();
if visible_items.len() == 1 {
if let Err(e) =
handle_selected_item(ui, meta, None, Some(visible_items[0].1.clone()), None)
{
log::error!("failed to handle selected item {e}");
}
}
}
drop(menu_rows);
if meta.config.read().unwrap().dynamic_lines() {
if let Some(geometry) = get_monitor_geometry(ui.window.surface().as_ref()) {
let height =