Rewrite Loc.MoveLA(n): do not call util.Abs(n) in cycle, cleaner code

This commit is contained in:
bibaka
2026-03-28 02:12:08 +03:00
parent 1be75cc697
commit 4ddf4fe2b1

View File

@@ -113,14 +113,13 @@ func (l Loc) left(buf *LineArray) Loc {
// MoveLA moves the cursor n characters to the left or right
// It moves the cursor left if n is negative
func (l Loc) MoveLA(n int, buf *LineArray) Loc {
if n > 0 {
for i := 0; i < n; i++ {
l = l.right(buf)
}
return l
for n > 0 {
l = l.right(buf)
n--
}
for i := 0; i < util.Abs(n); i++ {
for n < 0 {
l = l.left(buf)
n++
}
return l
}