Skip to content

Commit 25faa84

Browse files
authored
Fix documentation for Loc.LessThan() and other similar functions (#4058)
* Fix documentation for Loc.LessThan() and other similar functions * Rewrite Loc.MoveLA(n): do not call util.Abs(n) in cycle, cleaner code
2 parents 4d04ad7 + 4ddf4fe commit 25faa84

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

internal/buffer/loc.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,23 @@ type Loc struct {
99
X, Y int
1010
}
1111

12-
// LessThan returns true if b is smaller
12+
// LessThan returns true if l is smaller than b
1313
func (l Loc) LessThan(b Loc) bool {
1414
if l.Y < b.Y {
1515
return true
1616
}
1717
return l.Y == b.Y && l.X < b.X
1818
}
1919

20-
// GreaterThan returns true if b is bigger
20+
// GreaterThan returns true if l is bigger than b
2121
func (l Loc) GreaterThan(b Loc) bool {
2222
if l.Y > b.Y {
2323
return true
2424
}
2525
return l.Y == b.Y && l.X > b.X
2626
}
2727

28-
// GreaterEqual returns true if b is greater than or equal to b
28+
// GreaterEqual returns true if l is greater than or equal to b
2929
func (l Loc) GreaterEqual(b Loc) bool {
3030
if l.Y > b.Y {
3131
return true
@@ -36,7 +36,7 @@ func (l Loc) GreaterEqual(b Loc) bool {
3636
return l == b
3737
}
3838

39-
// LessEqual returns true if b is less than or equal to b
39+
// LessEqual returns true if l is less than or equal to b
4040
func (l Loc) LessEqual(b Loc) bool {
4141
if l.Y < b.Y {
4242
return true
@@ -113,14 +113,13 @@ func (l Loc) left(buf *LineArray) Loc {
113113
// MoveLA moves the cursor n characters to the left or right
114114
// It moves the cursor left if n is negative
115115
func (l Loc) MoveLA(n int, buf *LineArray) Loc {
116-
if n > 0 {
117-
for i := 0; i < n; i++ {
118-
l = l.right(buf)
119-
}
120-
return l
116+
for n > 0 {
117+
l = l.right(buf)
118+
n--
121119
}
122-
for i := 0; i < util.Abs(n); i++ {
120+
for n < 0 {
123121
l = l.left(buf)
122+
n++
124123
}
125124
return l
126125
}

0 commit comments

Comments
 (0)