From 4a8cae34fae8cf0641c1081592bd0c272c0a0d0b Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Wed, 18 Dec 2024 16:03:28 -0300 Subject: [PATCH] fix: do not navigate out to the right --- viewport/viewport.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/viewport/viewport.go b/viewport/viewport.go index 2ff0802..cfa6295 100644 --- a/viewport/viewport.go +++ b/viewport/viewport.go @@ -331,9 +331,23 @@ func (m *Model) MoveLeft() { // MoveRight moves all lines to set runes right. func (m *Model) MoveRight() { + // prevents over scrolling to the right + if m.indent >= m.longestLineWidth()-m.Width { + return + } m.indent += m.horizontalStep } +func (m Model) longestLineWidth() int { + w := 0 + for _, l := range m.lines { + if ww := ansi.StringWidth(l); ww > w { + w = ww + } + } + return w +} + // Resets lines indent to zero. func (m *Model) ResetIndent() { m.indent = 0