feat(viewport): horizontal scroll with mouse wheel

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:
Daan Schoone
2025-03-28 10:18:17 +01:00
parent 39668ec629
commit a0a432e11d
+20 -6
View File
@@ -466,16 +466,30 @@ func (m Model) updateAsModel(msg tea.Msg) (Model, tea.Cmd) {
}
switch msg.Button { //nolint:exhaustive
case tea.MouseButtonWheelUp:
lines := m.ScrollUp(m.MouseWheelDelta)
if m.HighPerformanceRendering {
cmd = ViewUp(m, lines)
if msg.Shift {
// Note that not every terminal emulator sends the shift event for mouse actions by default (looking at you Konsole)
m.ScrollLeft(m.horizontalStep)
} else {
lines := m.ScrollUp(m.MouseWheelDelta)
if m.HighPerformanceRendering {
cmd = ViewUp(m, lines)
}
}
case tea.MouseButtonWheelDown:
lines := m.ScrollDown(m.MouseWheelDelta)
if m.HighPerformanceRendering {
cmd = ViewDown(m, lines)
if msg.Shift {
m.ScrollRight(m.horizontalStep)
} 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)
}
}