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 38b4110aa..551da3c8f 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 @@ -40,7 +40,8 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at private val selectStart = arrayOf(0, 0, 0) private val selectEnd = arrayOf(0, 0, 0) private var textChapter: TextChapter? = null - private var textPage: TextPage = TextPage() + var textPage: TextPage = TextPage() + private set //滚动参数 private val pageFactory: TextPageFactory get() = callBack.pageFactory diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt index de97f062a..402666168 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt @@ -276,4 +276,5 @@ class PageView(context: Context) : FrameLayout(context) { val selectedText: String get() = binding.contentTextView.selectedText + val textPage get() = binding.contentTextView.textPage } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt index 4cab060e4..292d283dd 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt @@ -22,8 +22,11 @@ import io.legado.app.ui.book.read.page.provider.ChapterProvider import io.legado.app.ui.book.read.page.provider.TextPageFactory import io.legado.app.utils.activity import io.legado.app.utils.screenshot +import java.text.BreakIterator +import java.util.* import kotlin.math.abs + class ReadView(context: Context, attrs: AttributeSet) : FrameLayout(context, attrs), DataSource { @@ -250,8 +253,21 @@ class ReadView(context: Context, attrs: AttributeSet) : firstRelativePage = relativePage firstLineIndex = lineIndex firstCharIndex = charIndex + val boundary = BreakIterator.getWordInstance(Locale.getDefault()) + val lineText = curPage.textPage.textLines[lineIndex].text + boundary.setText(lineText) + var start = boundary.first() + var end = boundary.next() + while (end != BreakIterator.DONE) { + if (charIndex in start until end) { + firstCharIndex = start + break + } + start = end + end = boundary.next() + } curPage.selectStartMoveIndex(firstRelativePage, firstLineIndex, firstCharIndex) - curPage.selectEndMoveIndex(firstRelativePage, firstLineIndex, firstCharIndex) + curPage.selectEndMoveIndex(firstRelativePage, firstLineIndex, end - 1) } }