Skip to content

Commit

Permalink
feat: added new 'autoselect' option [per module or via flag]
Browse files Browse the repository at this point in the history
  • Loading branch information
abenz1267 committed Nov 12, 2024
1 parent d0cd79c commit 9fdce52
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 3 deletions.
5 changes: 5 additions & 0 deletions cmd/walker.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ func main() {
state.Benchmark = true
}

if slices.Contains(args, "-x") || slices.Contains(args, "--autoselect") {
state.AutoSelect = true
}

state.IsService = slices.Contains(args, "--gapplication-service")

if state.IsService {
Expand Down Expand Up @@ -96,6 +100,7 @@ func main() {

app := gtk.NewApplication(appName, gio.ApplicationHandlesCommandLine)

app.AddMainOption("autoselect", 'x', glib.OptionFlagNone, glib.OptionArgNone, "auto select only item in list", "")
app.AddMainOption("modules", 'm', glib.OptionFlagNone, glib.OptionArgString, "modules to be loaded", "the modules")
app.AddMainOption("new", 'n', glib.OptionFlagNone, glib.OptionArgNone, "start new instance ignoring service", "")
app.AddMainOption("keepsort", 'k', glib.OptionFlagNone, glib.OptionArgNone, "don't sort alphabetically", "")
Expand Down
1 change: 1 addition & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ type CustomCommand struct {
}

type GeneralModule struct {
AutoSelect bool `mapstructure:"auto_select"`
Delay int `mapstructure:"delay"`
EagerLoading bool `mapstructure:"eager_loading"`
History bool `mapstructure:"history"`
Expand Down
2 changes: 2 additions & 0 deletions internal/state/appstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (

type AppState struct {
ActiveItem *int
AutoSelect bool
AutoSelectOld bool
Clipboard modules.Workable
IsDebug bool
IsDmenu bool
Expand Down
14 changes: 11 additions & 3 deletions internal/ui/interactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -824,9 +824,16 @@ func processAsync(ctx context.Context, text string) {

tahAcceptedIdentifier = ""

if !layout.Window.Box.Search.Spinner.Hide {
elements.spinner.SetVisible(false)
}
glib.IdleAdd(func() {
if !layout.Window.Box.Search.Spinner.Hide {
elements.spinner.SetVisible(false)
}

if common.items.NItems() == 1 && appstate.AutoSelect {
common.selection.SelectItem(0, true)
activateItem(false, false, false)
}
})
}

func setTypeahead(modules []modules.Workable) {
Expand Down Expand Up @@ -933,6 +940,7 @@ func quit() {

appstate.IsRunning = false
appstate.IsSingle = false
appstate.AutoSelect = appstate.AutoSelectOld
// typeaheadSuggestionAccepted = ""
historyIndex = 0

Expand Down
6 changes: 6 additions & 0 deletions internal/ui/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ func setupSingleModule() {
singleModule = toUse[0]
}

appstate.AutoSelectOld = appstate.AutoSelect

if !appstate.AutoSelect {
appstate.AutoSelect = singleModule.General().AutoSelect
}

glib.IdleAdd(func() {
elements.input.SetObjectProperty("search-delay", singleModule.General().Delay)
})
Expand Down

0 comments on commit 9fdce52

Please sign in to comment.