From f3a9a70c73bf557f016bc797579f09957dd2b128 Mon Sep 17 00:00:00 2001 From: bloeys Date: Mon, 1 Aug 2022 03:41:14 +0400 Subject: [PATCH] Fix scrolling back causing empty lines sometimes --- main.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/main.go b/main.go index 79b5580..33ba43d 100755 --- a/main.go +++ b/main.go @@ -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' { - charsIntoLine := getCharGridPosX(it.Buf.Iterator(), paraIt, startIndex-2, charsPerLine) - if charsIntoLine > 0 { - charsSeenThisLine = charsPerLine - charsIntoLine + 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' { + // Skip the extra new line so the decoder starts with normal characters instead of seeing a newline + // and immediately quitting + if startIndexByte == '\n' || startMinusOneIndexByte == '\n' { it.Prev() }