diff --git a/internal/display/bufwindow.go b/internal/display/bufwindow.go index e1db946e..5c7c8912 100644 --- a/internal/display/bufwindow.go +++ b/internal/display/bufwindow.go @@ -219,7 +219,7 @@ func (w *BufWindow) Relocate() bool { w.StartLine = c ret = true } - if c.GreaterThan(w.Scroll(w.StartLine, height-1-scrollmargin)) && c.LessThan(w.Scroll(bEnd, -scrollmargin+1)) { + if c.GreaterThan(w.Scroll(w.StartLine, height-1-scrollmargin)) && c.LessEqual(w.Scroll(bEnd, -scrollmargin)) { w.StartLine = w.Scroll(c, -height+1+scrollmargin) ret = true } else if c.GreaterThan(w.Scroll(bEnd, -scrollmargin)) && c.GreaterThan(w.Scroll(w.StartLine, height-1)) { diff --git a/internal/display/softwrap.go b/internal/display/softwrap.go index 0597f061..29ddf001 100644 --- a/internal/display/softwrap.go +++ b/internal/display/softwrap.go @@ -30,6 +30,28 @@ func (s SLoc) GreaterThan(b SLoc) bool { return s.Line == b.Line && s.Row > b.Row } +// LessEqual returns true if s is less than or equal to b +func (s SLoc) LessEqual(b SLoc) bool { + if s.Line < b.Line { + return true + } + if s.Line == b.Line && s.Row < b.Row { + return true + } + return s == b +} + +// GreaterEqual returns true if s is bigger than or equal to b +func (s SLoc) GreaterEqual(b SLoc) bool { + if s.Line > b.Line { + return true + } + if s.Line == b.Line && s.Row > b.Row { + return true + } + return s == b +} + // VLoc represents a location in the buffer as a visual location in the // linewrapped buffer. type VLoc struct {