fix(tui): cancel queued wheel on key input
This commit is contained in:
parent
c48b77a27f
commit
3f824cb66f
24
tui/tui.go
24
tui/tui.go
@ -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())
|
||||
|
||||
@ -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",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user