From 48d91427f33e80f66e45e5e685b440634b1a43cb Mon Sep 17 00:00:00 2001 From: Massimo Mund Date: Thu, 7 Aug 2025 21:05:46 +0200 Subject: [PATCH] Make horizontal relocation (scrolling) respect selections Currently there is no logic to handle horizontal scrolling when text is selected. The current code only takes the cursor position into account. This only affects buffers where the `softwrap` option is disabled. --- internal/display/bufwindow.go | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/internal/display/bufwindow.go b/internal/display/bufwindow.go index 1ecb43236e..2f3e1ecbf2 100644 --- a/internal/display/bufwindow.go +++ b/internal/display/bufwindow.go @@ -244,18 +244,30 @@ func (w *BufWindow) Relocate() bool { // horizontal relocation (scrolling) if !b.Settings["softwrap"].(bool) { - cx := activeC.GetVisualX(false) + cxStart := activeC.GetVisualX(false) + cxEnd := cxStart + if activeC.HasSelection() { + sxStart := w.VLocFromLoc(activeC.CurSelection[0]).VisualX + if sxStart < cxEnd { + cxStart = sxStart + } + sxEnd := w.VLocFromLoc(activeC.CurSelection[1]).VisualX + if sxEnd > cxEnd { + cxEnd = sxEnd + } + } + rw := runewidth.RuneWidth(activeC.RuneUnder(activeC.X)) if rw == 0 { rw = 1 // tab or newline } - if cx < w.StartCol { - w.StartCol = cx + if cxStart < w.StartCol { + w.StartCol = cxStart ret = true } - if cx+rw > w.StartCol+w.bufWidth { - w.StartCol = cx - w.bufWidth + rw + if cxEnd+rw > w.StartCol+w.bufWidth { + w.StartCol = cxEnd - w.bufWidth + rw ret = true } }