From 97b46a5b2eb9fdda9f356655a43e812f997b7828 Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 9 Dec 2020 16:07:43 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E9=80=89=E6=8B=A9=E6=96=87=E6=9C=AC?= =?UTF-8?q?=E6=97=B6=E4=BC=98=E5=85=88=E9=80=89=E8=AF=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/page/ContentTextView.kt | 3 ++- .../legado/app/ui/book/read/page/PageView.kt | 1 + .../legado/app/ui/book/read/page/ReadView.kt | 18 +++++++++++++++++- 3 files changed, 20 insertions(+), 2 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 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) } } From 4bd52c18d19183a6dab5d33f015040b3bdb28393 Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 9 Dec 2020 16:08:54 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E9=80=89=E6=8B=A9=E6=96=87=E6=9C=AC?= =?UTF-8?q?=E6=97=B6=E4=BC=98=E5=85=88=E9=80=89=E8=AF=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/updateLog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 2ce28118f..92ceba84f 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -7,6 +7,7 @@ * 修复bug * 优化中文排序 * 优化编码识别 +* 选择文字时优先选词 **2020/12/06** * 添加规则订阅功能,订阅界面第一个图标,可以订阅书源/订阅源/替换规则