Skip to content

Commit 41f1c16

Browse files
authored
feat: add F1 key to toggle help overlay (#101)
## Summary - Add F1 as an additional key binding (alongside ?) to toggle the floating help menu - Esc, q, and ctrl+c close the help overlay instead of quitting when it's open - Block all other keys while the help overlay is visible - Update footer hint from "? help" to "F1/? help" ## Test plan - [x] Press F1 to open help overlay - [x] Press F1 again to close it - [x] Press ? to toggle help (still works) - [x] Press Esc to close help overlay - [x] Press q while help is open — should close overlay, not quit - [x] Press q while help is closed — should quit - [x] Press other keys while help is open — should be blocked
1 parent 2898ff7 commit 41f1c16

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

pkg/ui/keys.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ var keys = &KeyMap{
8383
key.WithHelp("i", "toggle icon style"),
8484
),
8585
ToggleHelp: key.NewBinding(
86-
key.WithKeys("?"),
87-
key.WithHelp("?", "toggle help"),
86+
key.WithKeys("?", "f1"),
87+
key.WithHelp("F1/?", "toggle help"),
8888
),
8989
}
9090

pkg/ui/tui.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,17 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
130130
switch msg := msg.(type) {
131131
case tea.KeyPressMsg:
132132
switch {
133-
case key.Matches(msg, keys.Quit):
134-
return m, tea.Quit
135133
case key.Matches(msg, keys.ToggleHelp):
136134
m.helpOpen = !m.helpOpen
135+
return m, tea.Batch(cmds...)
136+
case m.helpOpen && (key.Matches(msg, keys.Quit) || msg.Key().Code == tea.KeyEscape):
137+
m.helpOpen = false
138+
return m, tea.Batch(cmds...)
139+
case m.helpOpen:
140+
// Block all other keys while help is open
141+
return m, tea.Batch(cmds...)
142+
case key.Matches(msg, keys.Quit):
143+
return m, tea.Quit
137144
case key.Matches(msg, keys.Search):
138145
m.searching = true
139146
m.search.SetWidth(m.searchWidth())
@@ -471,7 +478,7 @@ func (m mainModel) footerView() string {
471478
files := fmt.Sprintf(" %d files", len(m.files))
472479
sep := lipgloss.NewStyle().Foreground(lipgloss.BrightBlack).Render(" • ")
473480
added, deleted := m.diffViewer.RootDiffStats()
474-
help := base.Background(lipgloss.BrightBlack).PaddingLeft(1).PaddingRight(1).Render("? help")
481+
help := base.Background(lipgloss.BrightBlack).PaddingLeft(1).PaddingRight(1).Render("F1/? help")
475482
stats := filenode.ViewDiffStats(added, deleted, base)
476483
spacing := base.Render(strings.Repeat(" ", max(0, m.width-lipgloss.Width(stats)-
477484
lipgloss.Width(help)-lipgloss.Width(files)-lipgloss.Width(sep))))

0 commit comments

Comments
 (0)