From 97b76f67dd8c4ff00c3377bc062edf89511788bc Mon Sep 17 00:00:00 2001 From: Andrej Benz Date: Tue, 18 Feb 2025 14:25:30 +0100 Subject: [PATCH] all: added 'keep_selection' to general module config to avoid selecting first item on query change --- internal/config/config.default.toml | 1 + internal/config/config.go | 1 + internal/ui/ui.go | 14 +++++++++++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/internal/config/config.default.toml b/internal/config/config.default.toml index 7f62c65..6f8ca60 100644 --- a/internal/config/config.default.toml +++ b/internal/config/config.default.toml @@ -206,6 +206,7 @@ placeholder = "Switcher" prefix = "/" [builtins.websearch] +keep_selection = true weight = 5 icon = "applications-internet" name = "websearch" diff --git a/internal/config/config.go b/internal/config/config.go index 468fbc2..6205879 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -205,6 +205,7 @@ type GeneralModule struct { History bool `koanf:"history"` HistoryBlacklist []Blacklist `koanf:"history_blacklist"` Icon string `koanf:"icon"` + KeepSelection bool `koanf:"keep_selection"` KeepSort bool `koanf:"keep_sort"` MinChars int `koanf:"min_chars"` Name string `koanf:"name"` diff --git a/internal/ui/ui.go b/internal/ui/ui.go index 3c69aca..2544ea8 100644 --- a/internal/ui/ui.go +++ b/internal/ui/ui.go @@ -891,7 +891,19 @@ func afterUI() { elements.listPlaceholder.SetVisible(false) } - common.selection.SetSelected(0) + if len(toUse) == 1 || singleModule != nil { + module := singleModule + + if module == nil { + module = toUse[0] + } + + if !module.General().KeepSelection { + common.selection.SetSelected(0) + } + } else { + common.selection.SetSelected(0) + } if common.items.NItems() == 1 { entry := gioutil.ObjectValue[util.Entry](common.items.Item(0))