mirror of
https://github.com/jroimartin/gocui.git
synced 2025-04-28 13:48:51 +08:00
better autoscroll behaviour
This commit is contained in:
parent
b2fc03c74a
commit
b8e4f0899f
17
view.go
17
view.go
@ -809,8 +809,9 @@ func (v *View) draw() error {
|
||||
}
|
||||
}
|
||||
|
||||
if v.Autoscroll && len(v.viewLines) > maxY {
|
||||
v.oy = len(v.viewLines) - maxY
|
||||
visibleViewLinesHeight := v.viewLineLengthIgnoringTrailingBlankLines()
|
||||
if v.Autoscroll && visibleViewLinesHeight > maxY {
|
||||
v.oy = visibleViewLinesHeight - maxY
|
||||
}
|
||||
y := 0
|
||||
for i, vline := range v.viewLines {
|
||||
@ -858,6 +859,18 @@ func (v *View) draw() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// if autoscroll is enabled but we only have a single row of cells shown to the
|
||||
// user, we don't want to scroll to the final line if it contains no text. So
|
||||
// this tells us the view lines height when we ignore any trailing blank lines
|
||||
func (v *View) viewLineLengthIgnoringTrailingBlankLines() int {
|
||||
for i := len(v.viewLines) - 1; i >= 0; i-- {
|
||||
if len(v.viewLines[i].line) > 0 {
|
||||
return i + 1
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (v *View) isPatternMatchedRune(x, y int) (bool, bool) {
|
||||
searchStringLength := len(v.searcher.searchString)
|
||||
for i, pos := range v.searcher.searchPositions {
|
||||
|
Loading…
x
Reference in New Issue
Block a user