Skip to content

Commit

Permalink
[feature]<main>: ? as dy keyword switch ✨✨ (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
o98k-ok committed Jul 4, 2024
1 parent 4d210ee commit c1fdac0
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions internal/ui/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ func (ie *InputElem) Init() tea.Cmd {
}

func (ie *InputElem) View() string {
ie.textInput.Placeholder = ie.suggestKey
if len(ie.suggestKeys) > 0 {
ie.textInput.Placeholder = ie.suggestKey
}
border := lipgloss.RoundedBorder()
box := lipgloss.NewStyle().
BorderStyle(border).
Expand Down Expand Up @@ -117,6 +119,20 @@ func (ie *InputElem) MsgKeyBindings() map[string]map[string]func(v interface{})
}
return cmd
},
"?": func(v interface{}) tea.Cmd {
if !ie.active {
return nil
}

switch {
case ie.textInput.Focused():
if len(ie.suggestKeys) > 0 {
ie.textInput.SetValue(ie.suggestKey)
ie.suggestKey = ie.suggestKeys[random.RandInt(0, len(ie.suggestKeys))]
}
}
return nil
},
"down": func(v interface{}) tea.Cmd {
if !ie.active {
return nil
Expand Down Expand Up @@ -182,9 +198,6 @@ func (ie *InputElem) MsgKeyBindings() map[string]map[string]func(v interface{})
ie.fetcherIdx += 1
pack := ie.fetch(ie.fetcherIdx)
ie.result.ResetList(pack)
case ie.textInput.Focused():
ie.textInput.SetValue(ie.suggestKey)
ie.suggestKey = ie.suggestKeys[random.RandInt(0, len(ie.suggestKeys))]
}
return nil
},
Expand Down

0 comments on commit c1fdac0

Please sign in to comment.