Fix scrolling back causing empty lines sometimes

This commit is contained in:
bloeys
2022-08-01 03:41:14 +04:00
parent 05fb837400
commit f3a9a70c73

11
main.go
View File

@ -965,17 +965,22 @@ func FindNLinesIndexIterator(it ring.Iterator[byte], paraIt ring.Iterator[Para],
// If on the empty line between paragraphs we want to know where the last char of the previous
// para is so we can take into account position differences with wrapping
if it.Buf.Get(uint64(startIndex)) == '\n' && it.Buf.Get(uint64(startIndex-1)) == '\n' {
startIndexByte := it.Buf.Get(uint64(startIndex))
startMinusOneIndexByte := it.Buf.Get(uint64(startIndex - 1))
if startIndexByte == '\n' {
if startMinusOneIndexByte == '\n' {
charsIntoLine := getCharGridPosX(it.Buf.Iterator(), paraIt, startIndex-2, charsPerLine)
if charsIntoLine > 0 {
charsSeenThisLine = charsPerLine - charsIntoLine
}
}
}
// Skip the extra new line so the decoder starts with normal characters instead of seeing a newline
// and immediately quitting
it.Prev()
} else if it.Buf.Get(uint64(startIndex-1)) == '\n' {
if startIndexByte == '\n' || startMinusOneIndexByte == '\n' {
it.Prev()
}