选择文本时优先选词

pull/540/head
gedoor 4 years ago
parent a6f83282c3
commit 97b46a5b2e
  1. 3
      app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt
  2. 1
      app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt
  3. 18
      app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt

@ -40,7 +40,8 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
private val selectStart = arrayOf(0, 0, 0) private val selectStart = arrayOf(0, 0, 0)
private val selectEnd = arrayOf(0, 0, 0) private val selectEnd = arrayOf(0, 0, 0)
private var textChapter: TextChapter? = null private var textChapter: TextChapter? = null
private var textPage: TextPage = TextPage() var textPage: TextPage = TextPage()
private set
//滚动参数 //滚动参数
private val pageFactory: TextPageFactory get() = callBack.pageFactory private val pageFactory: TextPageFactory get() = callBack.pageFactory

@ -276,4 +276,5 @@ class PageView(context: Context) : FrameLayout(context) {
val selectedText: String get() = binding.contentTextView.selectedText val selectedText: String get() = binding.contentTextView.selectedText
val textPage get() = binding.contentTextView.textPage
} }

@ -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.ui.book.read.page.provider.TextPageFactory
import io.legado.app.utils.activity import io.legado.app.utils.activity
import io.legado.app.utils.screenshot import io.legado.app.utils.screenshot
import java.text.BreakIterator
import java.util.*
import kotlin.math.abs import kotlin.math.abs
class ReadView(context: Context, attrs: AttributeSet) : class ReadView(context: Context, attrs: AttributeSet) :
FrameLayout(context, attrs), FrameLayout(context, attrs),
DataSource { DataSource {
@ -250,8 +253,21 @@ class ReadView(context: Context, attrs: AttributeSet) :
firstRelativePage = relativePage firstRelativePage = relativePage
firstLineIndex = lineIndex firstLineIndex = lineIndex
firstCharIndex = charIndex 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.selectStartMoveIndex(firstRelativePage, firstLineIndex, firstCharIndex)
curPage.selectEndMoveIndex(firstRelativePage, firstLineIndex, firstCharIndex) curPage.selectEndMoveIndex(firstRelativePage, firstLineIndex, end - 1)
} }
} }

Loading…
Cancel
Save