fix: sluggish mouse scroll

This commit is contained in:
2026-07-30 14:57:16 +02:00
parent 21d44ea3a1
commit b24669e604
11 changed files with 218 additions and 6 deletions

48
tui.go
View File

@@ -34,6 +34,8 @@ const (
type tickMsg time.Time
type pathTickMsg time.Time
const mouseWheelScrollStep = 3
type writeMode int
const (
@@ -703,6 +705,9 @@ func (m App) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if tick, ok := msg.(diffletTickMsg); ok {
return m, m.difflet.update(tick)
}
if mouse, ok := msg.(tea.MouseMsg); ok && m.handleMouseWheel(mouse) {
return m, nil
}
if m.aiMode != aiNone {
if updated, command, handled := m.updateAI(msg); handled {
return updated, command
@@ -1887,6 +1892,49 @@ func (m *App) page(direction int) {
m.move(direction * max(3, m.height/2))
}
func (m *App) handleMouseWheel(message tea.MouseMsg) bool {
if message.Action != tea.MouseActionPress {
return false
}
direction := 0
switch message.Button {
case tea.MouseButtonWheelUp:
direction = -1
case tea.MouseButtonWheelDown:
direction = 1
default:
return false
}
delta := direction * mouseWheelScrollStep
if m.helpVisible {
m.helpScroll = clamp(m.helpScroll+delta, 0, m.helpMaxScroll())
return true
}
if m.aiMode == aiConfirm {
m.aiPreviewScroll = max(0, m.aiPreviewScroll+delta)
return true
}
if m.aiMode != aiNone && m.aiMode != aiDiscussion {
return true
}
switch m.screen {
case dashboardScreen:
m.scrollDashboard(delta)
case healthScreen:
m.healthScroll = clamp(m.healthScroll+delta, 0, m.healthMaxScroll())
case threadScreen:
if m.focus == threadDetailPane || m.writeMode == writeReply ||
m.aiMode == aiDiscussion {
m.scrollDetail(delta)
} else {
m.move(delta)
}
case prScreen:
m.move(delta)
}
return true
}
func (m *App) scrollDetail(delta int) {
m.scroll = clamp(m.scroll+delta, 0, m.detailMaxScroll())
m.acknowledgeVisibleUnread()