From a0a432e11dc045b7b950234436d06510ebf02fcb Mon Sep 17 00:00:00 2001 From: Daan Schoone Date: Tue, 25 Mar 2025 14:48:24 +0100 Subject: [PATCH] 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. --- viewport/viewport.go | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/viewport/viewport.go b/viewport/viewport.go index 4dc1c68..b9bccdf 100644 --- a/viewport/viewport.go +++ b/viewport/viewport.go @@ -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) } }