Skip to content

Commit

Permalink
fix: fix crash on empty inputhistory, update inputhistory accordingly
Browse files Browse the repository at this point in the history
  • Loading branch information
abenz1267 committed Jul 11, 2024
1 parent 17d0e96 commit 86f000f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion history/inputhistory.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

type InputHistory []string

func (h InputHistory) SaveToInputHistory(input string) {
func (h InputHistory) SaveToInputHistory(input string) InputHistory {
i := slices.Index(h, input)

if i != -1 {
Expand All @@ -23,6 +23,8 @@ func (h InputHistory) SaveToInputHistory(input string) {
}

util.ToGob(&h, filepath.Join(util.CacheDir(), "inputhistory.gob"))

return h
}

func GetInputHistory() InputHistory {
Expand Down
4 changes: 2 additions & 2 deletions ui/interactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ func handleSearchKeysPressed(val uint, code uint, modifier gdk.ModifierType) boo
case gdk.KEY_Down:
selectNext()
case gdk.KEY_Up:
if ui.selection.Selected() == 0 {
if ui.selection.Selected() == 0 && len(inputhstry) > 0 {
currentInput := ui.search.Text()

if currentInput != "" && !slices.Contains(inputhstry, currentInput) {
Expand Down Expand Up @@ -492,7 +492,7 @@ func activateItem(keepOpen, selectNext bool) {
hstry.Save(entry.Identifier(), strings.TrimSpace(ui.search.Text()))
}

inputhstry.SaveToInputHistory(ui.search.Text())
inputhstry = inputhstry.SaveToInputHistory(ui.search.Text())

err := cmd.Start()
if err != nil {
Expand Down

0 comments on commit 86f000f

Please sign in to comment.