fix: do not navigate out to the right

This commit is contained in:
Carlos Alexandro Becker
2024-12-18 16:03:28 -03:00
parent f1307e54de
commit 4a8cae34fa
+14
View File
@@ -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