From de8447a30c56a311e41549b80ccfca3d929d6051 Mon Sep 17 00:00:00 2001 From: o98k-ok Date: Thu, 4 Jul 2024 09:42:42 +0800 Subject: [PATCH] =?UTF-8?q?[feature]
:=20=3F=20as=20dy=20keyword=20sw?= =?UTF-8?q?itch=20=E2=9C=A8=E2=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/ui/input.go | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/internal/ui/input.go b/internal/ui/input.go index 14e47aa..ee2a249 100644 --- a/internal/ui/input.go +++ b/internal/ui/input.go @@ -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). @@ -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 @@ -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 },