Skip to content

Commit ff9245b

Browse files
committed
Implement help scrolling
1 parent 9390d5c commit ff9245b

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

internal/ui/app.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ type model struct {
7777
historyList list.Model
7878
currentView view
7979
showHelp bool
80+
helpOffset int
8081
matchFilterType matchFilterType
8182
statusMsgType statusMsgType
8283
w, h int
@@ -95,6 +96,7 @@ func newModel(allTestItems, historyItems []list.Item, defaultView view, defaultF
9596
historyList: historyList,
9697
currentView: defaultView,
9798
showHelp: false,
99+
helpOffset: 0,
98100
matchFilterType: defaultFilterType,
99101
statusMsgType: noneStatusMsgType,
100102
allBeforeSelected: -1,
@@ -197,7 +199,16 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
197199
}
198200

199201
if m.showHelp {
200-
if msg.String() == "?" || msg.String() == "backspace" || msg.String() == "ctrl+h" {
202+
switch msg.String() {
203+
case "up", "k":
204+
if m.helpOffset > 0 {
205+
m.helpOffset--
206+
}
207+
case "down", "j":
208+
if m.helpOffset < len(helpItems())-1 {
209+
m.helpOffset++
210+
}
211+
case "?", "backspace", "ctrl+h":
201212
m.showHelp = false
202213
}
203214
return m, nil
@@ -219,6 +230,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
219230
}
220231
case "?":
221232
m.showHelp = true
233+
m.helpOffset = 0
222234
return m, nil
223235
}
224236
}
@@ -323,7 +335,10 @@ func (m model) helpView() string {
323335
contentHeight := m.h - 5
324336
keyLines := []string{}
325337
descLines := []string{}
326-
for _, h := range helpItems() {
338+
for i, h := range helpItems() {
339+
if i < m.helpOffset {
340+
continue
341+
}
327342
if len(keyLines) >= contentHeight {
328343
break
329344
}

0 commit comments

Comments
 (0)