From ad72d779ca3292abc21afc81d537d2e9a3db2558 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 15 Apr 2022 13:35:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/book/read/page/ContentTextView.kt | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt index 68bd01393..057ce29bd 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt @@ -392,11 +392,12 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at pos.lineIndex = lineIndex textLine.textChars.forEachIndexed { charIndex, textChar -> pos.charIndex = charIndex - if (pos.compare(selectStart) >= 0 - && pos.compare(selectEnd) <= 0 - ) { + val compareStart = pos.compare(selectStart) + val compareEnd = pos.compare(selectEnd) + if (compareStart >= 0 && compareEnd <= 0) { builder.append(textChar.charData) - if (charIndex == textLine.charSize - 1 + if (compareEnd != 0 + && charIndex == textLine.charSize - 1 && textLine.text.endsWith("\n") ) { builder.append("\n") @@ -405,9 +406,6 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } } } - if (builder.endsWith("\n")) { - return builder.substring(0, builder.lastIndex) - } return builder.toString() }