diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index a0b8ef515..4a2c8db88 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -784,7 +784,7 @@ class ReadBookActivity : ReadBookBaseActivity(), super.onActivityResult(requestCode, resultCode, data) if (resultCode == Activity.RESULT_OK) { when (requestCode) { - requestCodeEditSource -> viewModel.upBookSource() { + requestCodeEditSource -> viewModel.upBookSource { upView() } requestCodeChapterList -> 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 4d431f8a5..24eebb6d1 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 @@ -347,8 +347,8 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at selectStart[0] = relativePage selectStart[1] = lineIndex selectStart[2] = charIndex - val textLine = relativePage(relativePage).textLines[lineIndex] - val textChar = textLine.textChars[charIndex] + val textLine = relativePage(relativePage).getLine(lineIndex) + val textChar = textLine.getTextChar(charIndex) upSelectedStart( textChar.start, textLine.lineBottom + relativeOffset(relativePage), @@ -364,8 +364,8 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at selectEnd[0] = relativePage selectEnd[1] = lineIndex selectEnd[2] = charIndex - val textLine = relativePage(relativePage).textLines[lineIndex] - val textChar = textLine.textChars[charIndex] + val textLine = relativePage(relativePage).getLine(lineIndex) + val textChar = textLine.getTextChar(lineIndex) upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset(relativePage)) upSelectChars() } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt index d921a217e..9d73757bb 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt @@ -28,8 +28,10 @@ data class TextLine( textChars.add(TextChar(charData, start = start, end = end)) } - fun getTextCharAt(index: Int): TextChar { - return textChars[index] + fun getTextChar(index: Int): TextChar { + return textChars.getOrElse(index) { + textChars.last() + } } fun getTextCharReverseAt(index: Int): TextChar { diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt index e2d291141..ba57dbc48 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt @@ -25,6 +25,12 @@ data class TextPage( val lineSize get() = textLines.size val charSize get() = text.length + fun getLine(index: Int): TextLine { + return textLines.getOrElse(index) { + textLines.last() + } + } + fun upLinesPosition() = ChapterProvider.apply { if (!ReadBookConfig.textBottomJustify) return@apply if (textLines.size <= 1) return@apply