1
1
mirror of https://github.com/walles/moar.git synced 2024-09-11 12:15:43 +03:00

Fix the final test failure

This commit is contained in:
Johan Walles 2022-09-25 08:22:47 +02:00
parent 210c5c1b33
commit 1fa95284a1
2 changed files with 24 additions and 10 deletions

View File

@ -96,8 +96,9 @@ func (p *Pager) renderScreenLines() (lines [][]twin.Cell, statusText string) {
// The returned lines are display ready, meaning that they come with horizontal // The returned lines are display ready, meaning that they come with horizontal
// scroll markers and line numbers as necessary. // scroll markers and line numbers as necessary.
// //
// The maximum number of lines returned by this method will be one less than the // The maximum number of lines returned by this method is limited by the screen
// screen height, leaving space for the status line. // height. If the status line is visible, you'll get at most one less than the
// screen height from this method.
func (p *Pager) renderLines() ([]renderedLine, string) { func (p *Pager) renderLines() ([]renderedLine, string) {
_, height := p.screen.Size() _, height := p.screen.Size()
wantedLineCount := height - 1 wantedLineCount := height - 1

View File

@ -268,11 +268,12 @@ func (p *Pager) scrollToEnd() {
if inputLineCount == 0 { if inputLineCount == 0 {
return return
} }
lastInputLineNumberOneBased := inputLineCount
inputLine := p.reader.GetLine(inputLineCount) lastInputLine := p.reader.GetLine(lastInputLineNumberOneBased)
screenLines := p.renderLine(inputLine, 0) screenLines := p.renderLine(lastInputLine, lastInputLineNumberOneBased)
p.scrollPosition.internalDontTouch.lineNumberOneBased = inputLineCount p.scrollPosition.internalDontTouch.lineNumberOneBased = lastInputLineNumberOneBased
p.scrollPosition.internalDontTouch.deltaScreenLines = len(screenLines) - 1 p.scrollPosition.internalDontTouch.deltaScreenLines = len(screenLines) - 1
} }
@ -280,14 +281,26 @@ func (p *Pager) scrollToEnd() {
// has pressed the down arrow enough times. // has pressed the down arrow enough times.
func (p *Pager) isScrolledToEnd() bool { func (p *Pager) isScrolledToEnd() bool {
inputLineCount := p.reader.GetLineCount() inputLineCount := p.reader.GetLineCount()
lastInputLineOneBased := inputLineCount if inputLineCount == 0 {
lastVisiblePosition := p.getLastVisiblePosition()
if lastVisiblePosition == nil {
// No lines available, which means we can't scroll any further down // No lines available, which means we can't scroll any further down
return true return true
} }
return lastVisiblePosition.internalDontTouch.lineNumberOneBased == lastInputLineOneBased lastInputLineNumberOneBased := inputLineCount
visibleLines, _ := p.renderLines()
lastVisibleLine := visibleLines[len(visibleLines)-1]
if lastVisibleLine.inputLineOneBased != lastInputLineNumberOneBased {
// Last input line is not on the screen
return false
}
lastInputLine := p.reader.GetLine(lastInputLineNumberOneBased)
lastInputLineRendered := p.renderLine(lastInputLine, lastInputLineNumberOneBased)
lastRenderedSubLine := lastInputLineRendered[len(lastInputLineRendered)-1]
// If the last visible subline is the same as the last possible subline then
// we're at the bottom
return lastVisibleLine.wrapIndex == lastRenderedSubLine.wrapIndex
} }
// Returns nil if there are no lines // Returns nil if there are no lines