feat(viewport): horizontal scroll with mouse wheel (#761)

Add support for the events of a horizontal mouse wheel and when holding
shift while using the regular mouse wheel now scrolls the screen left
and right.
This commit is contained in:
Unseen Daan
2025-03-28 13:59:12 -03:00
committed by GitHub
parent 39668ec629
commit ea344ab907
+20 -6
View File
@@ -466,16 +466,30 @@ func (m Model) updateAsModel(msg tea.Msg) (Model, tea.Cmd) {
} }
switch msg.Button { //nolint:exhaustive switch msg.Button { //nolint:exhaustive
case tea.MouseButtonWheelUp: case tea.MouseButtonWheelUp:
lines := m.ScrollUp(m.MouseWheelDelta) if msg.Shift {
if m.HighPerformanceRendering { // Note that not every terminal emulator sends the shift event for mouse actions by default (looking at you Konsole)
cmd = ViewUp(m, lines) m.ScrollLeft(m.horizontalStep)
} else {
lines := m.ScrollUp(m.MouseWheelDelta)
if m.HighPerformanceRendering {
cmd = ViewUp(m, lines)
}
} }
case tea.MouseButtonWheelDown: case tea.MouseButtonWheelDown:
lines := m.ScrollDown(m.MouseWheelDelta) if msg.Shift {
if m.HighPerformanceRendering { m.ScrollRight(m.horizontalStep)
cmd = ViewDown(m, lines) } else {
lines := m.ScrollDown(m.MouseWheelDelta)
if m.HighPerformanceRendering {
cmd = ViewDown(m, lines)
}
} }
// Note that not every terminal emulator sends the horizontal wheel events by default (looking at you Konsole)
case tea.MouseButtonWheelLeft:
m.ScrollLeft(m.horizontalStep)
case tea.MouseButtonWheelRight:
m.ScrollRight(m.horizontalStep)
} }
} }