Skip to content

Commit 8ff7ec5

Browse files
authored
Fix relocate at the end of buffer when scrollmargin is 0 (micro-editor#2578)
* Add LessEqual and GreaterEqual for SLoc * Fix relocate at the end of buffer when scrollmargin is 0 Fix the following issue: when scrollmargin is set to 0 and we move the cursor to the end of buffer (e.g. via Ctrl-End), the buffer view doesn't move. The cause is that the condition c.LessThan(w.Scroll(bEnd, -scrollmargin+1)) doesn't hold, since Scroll() takes care not to return a location beyond the end of buffer, so in this case Scroll() just returns bEnd.
1 parent 4864590 commit 8ff7ec5

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

internal/display/bufwindow.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ func (w *BufWindow) Relocate() bool {
219219
w.StartLine = c
220220
ret = true
221221
}
222-
if c.GreaterThan(w.Scroll(w.StartLine, height-1-scrollmargin)) && c.LessThan(w.Scroll(bEnd, -scrollmargin+1)) {
222+
if c.GreaterThan(w.Scroll(w.StartLine, height-1-scrollmargin)) && c.LessEqual(w.Scroll(bEnd, -scrollmargin)) {
223223
w.StartLine = w.Scroll(c, -height+1+scrollmargin)
224224
ret = true
225225
} else if c.GreaterThan(w.Scroll(bEnd, -scrollmargin)) && c.GreaterThan(w.Scroll(w.StartLine, height-1)) {

internal/display/softwrap.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,28 @@ func (s SLoc) GreaterThan(b SLoc) bool {
3030
return s.Line == b.Line && s.Row > b.Row
3131
}
3232

33+
// LessEqual returns true if s is less than or equal to b
34+
func (s SLoc) LessEqual(b SLoc) bool {
35+
if s.Line < b.Line {
36+
return true
37+
}
38+
if s.Line == b.Line && s.Row < b.Row {
39+
return true
40+
}
41+
return s == b
42+
}
43+
44+
// GreaterEqual returns true if s is bigger than or equal to b
45+
func (s SLoc) GreaterEqual(b SLoc) bool {
46+
if s.Line > b.Line {
47+
return true
48+
}
49+
if s.Line == b.Line && s.Row > b.Row {
50+
return true
51+
}
52+
return s == b
53+
}
54+
3355
// VLoc represents a location in the buffer as a visual location in the
3456
// linewrapped buffer.
3557
type VLoc struct {

0 commit comments

Comments
 (0)