From 1be75cc6971bd1839eec001995dc1871f4dc350f Mon Sep 17 00:00:00 2001 From: bibaka <32kb@bk.ru> Date: Sat, 28 Mar 2026 02:09:00 +0300 Subject: [PATCH 1/2] Fix documentation for Loc.LessThan() and other similar functions --- internal/buffer/loc.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/buffer/loc.go b/internal/buffer/loc.go index 5566a7f9a8..a1237dadb9 100644 --- a/internal/buffer/loc.go +++ b/internal/buffer/loc.go @@ -9,7 +9,7 @@ type Loc struct { X, Y int } -// LessThan returns true if b is smaller +// LessThan returns true if l is smaller than b func (l Loc) LessThan(b Loc) bool { if l.Y < b.Y { return true @@ -17,7 +17,7 @@ func (l Loc) LessThan(b Loc) bool { return l.Y == b.Y && l.X < b.X } -// GreaterThan returns true if b is bigger +// GreaterThan returns true if l is bigger than b func (l Loc) GreaterThan(b Loc) bool { if l.Y > b.Y { return true @@ -25,7 +25,7 @@ func (l Loc) GreaterThan(b Loc) bool { return l.Y == b.Y && l.X > b.X } -// GreaterEqual returns true if b is greater than or equal to b +// GreaterEqual returns true if l is greater than or equal to b func (l Loc) GreaterEqual(b Loc) bool { if l.Y > b.Y { return true @@ -36,7 +36,7 @@ func (l Loc) GreaterEqual(b Loc) bool { return l == b } -// LessEqual returns true if b is less than or equal to b +// LessEqual returns true if l is less than or equal to b func (l Loc) LessEqual(b Loc) bool { if l.Y < b.Y { return true From 4ddf4fe2b1e0f64d26684fd0f7488c6cac7dc0ac Mon Sep 17 00:00:00 2001 From: bibaka <32kb@bk.ru> Date: Sat, 28 Mar 2026 02:12:08 +0300 Subject: [PATCH 2/2] Rewrite Loc.MoveLA(n): do not call util.Abs(n) in cycle, cleaner code --- internal/buffer/loc.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/internal/buffer/loc.go b/internal/buffer/loc.go index a1237dadb9..680b63a143 100644 --- a/internal/buffer/loc.go +++ b/internal/buffer/loc.go @@ -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 }