fix(tui): cancel queued wheel on key input

This commit is contained in:
Vincent Koc 2026-05-02 09:42:47 -07:00
parent c48b77a27f
commit 3f824cb66f
No known key found for this signature in database
2 changed files with 36 additions and 12 deletions

View File

@ -447,18 +447,18 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.focus = nextFocus(m.focus, 1)
case "shift+tab", "left":
m.focus = nextFocus(m.focus, -1)
case "up", "k":
if m.focus == focusRows {
m.move(-1)
} else {
m.scrollFocused(-1)
}
case "down", "j":
if m.focus == focusRows {
m.move(1)
} else {
m.scrollFocused(1)
}
case "up", "k":
if m.focus == focusRows {
m.move(-1)
} else {
m.scrollFocused(-1)
}
case "down", "j":
if m.focus == focusRows {
m.move(1)
} else {
m.scrollFocused(1)
}
case "pgup", "ctrl+b":
if m.focus == focusRows {
m.move(-m.pageSize())

View File

@ -200,6 +200,30 @@ func TestMouseWheelBurstsAreBuffered(t *testing.T) {
}
}
func TestKeyInputCancelsQueuedWheel(t *testing.T) {
items := make([]Item, 0, 10)
for i := 0; i < 10; i++ {
items = append(items, Item{Title: fmt.Sprintf("row %02d", i), Tags: []string{"message"}})
}
m := newModel(Options{Title: "archive", Items: items})
updated, cmd := m.Update(tea.MouseMsg{Type: tea.MouseWheelDown})
m = updated.(model)
if cmd == nil || !m.wheelPending {
t.Fatal("wheel should queue before key input")
}
seq := m.wheelSeq
updated, _ = m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'j'}})
m = updated.(model)
if m.wheelPending || m.wheelDelta != 0 {
t.Fatalf("key input did not cancel queued wheel: pending=%v delta=%d", m.wheelPending, m.wheelDelta)
}
updated, _ = m.Update(wheelScrollMsg{seq: seq})
m = updated.(model)
if m.selected != 1 {
t.Fatalf("stale wheel changed selection after key input, selected=%d", m.selected)
}
}
func TestMouseWheelTargetsPaneUnderPointer(t *testing.T) {
m := newModel(Options{
Title: "discrawl archive",