Skip to content

Commit b53226e

Browse files
authored
refactor: build the copy-as shortcut hint from the formats (#503)
The hint bar's y/J/t chip was a hardcoded literal that could drift from the picker's actual ShortcutKey dispatch; derive it from the open picker's format list instead.
1 parent e77eac6 commit b53226e

2 files changed

Lines changed: 21 additions & 10 deletions

File tree

internal/app/copy_format_picker_keys.go

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,32 @@
11
package app
22

33
import (
4+
"strings"
5+
46
tea "github.com/charmbracelet/bubbletea"
57

68
"github.com/janosmiko/lfk/internal/ui"
79
)
810

9-
// copyFormatPickerHints is the copy-as picker's bottom hint bar
10-
// (kept here to co-locate the feature and keep overlay_hintbar.go
11-
// under the file-length cap).
12-
func copyFormatPickerHints() []ui.HintEntry {
13-
return []ui.HintEntry{
14-
{Key: "j/k", Desc: "navigate"},
15-
{Key: "y/J/t", Desc: "shortcut"},
16-
{Key: "enter", Desc: "apply"},
17-
{Key: "esc", Desc: "cancel"},
11+
// copyFormatPickerHints is the copy-as picker's bottom hint bar (kept
12+
// here to co-locate the feature and keep overlay_hintbar.go under the
13+
// file-length cap). The shortcut chip is built from the open picker's
14+
// actual formats so it cannot drift from the ShortcutKey dispatch.
15+
func (m Model) copyFormatPickerHints() []ui.HintEntry {
16+
keys := make([]string, 0, len(m.copyFormatPicker.formats))
17+
for _, f := range m.copyFormatPicker.formats {
18+
if k := f.ShortcutKey(); k != "" {
19+
keys = append(keys, k)
20+
}
21+
}
22+
hints := []ui.HintEntry{{Key: "j/k", Desc: "navigate"}}
23+
if len(keys) > 0 {
24+
hints = append(hints, ui.HintEntry{Key: strings.Join(keys, "/"), Desc: "shortcut"})
1825
}
26+
return append(hints,
27+
ui.HintEntry{Key: "enter", Desc: "apply"},
28+
ui.HintEntry{Key: "esc", Desc: "cancel"},
29+
)
1930
}
2031

2132
// handleCopyFormatPickerKey routes key events to the active copy-as

internal/app/overlay_hintbar.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func (m Model) overlayHintBarSelector() string {
142142
{Key: "esc", Desc: "close"},
143143
})
144144
case overlayCopyFormat:
145-
return m.renderHints(copyFormatPickerHints())
145+
return m.renderHints(m.copyFormatPickerHints())
146146
case overlayCopyField:
147147
return m.renderHints(copyFieldPickerHints())
148148
case overlayTaintEditor:

0 commit comments

Comments
 (0)