From c0f4fd3923ba3ed1cd1054d3baba6980672f46a9 Mon Sep 17 00:00:00 2001 From: Horis <8674809+821938089@users.noreply.github.com> Date: Sun, 14 Jul 2024 21:36:13 +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 --- .../app/ui/book/read/page/ContentTextView.kt | 67 ++++++------------- 1 file changed, 19 insertions(+), 48 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 22a84c6c6c3e..7b37be544869 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 @@ -27,6 +27,7 @@ import io.legado.app.utils.getCompatColor import io.legado.app.utils.showDialogFragment import io.legado.app.utils.toastOnUi import java.util.concurrent.Executors +import kotlin.math.max import kotlin.math.min /** @@ -271,29 +272,19 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at * 开始选择符移动 */ fun selectStartMove(x: Float, y: Float) { - touchRough(x, y) { relativeOffset, textPos, _, textLine, textColumn -> + touchRough(x, y) { _, textPos, _, _, _ -> if (selectStart.compare(textPos) == 0) { return@touchRough } if (textPos.compare(selectEnd) <= 0) { - selectStart.upData(pos = textPos) - upSelectedStart( - if (textPos.columnIndex < textLine.columns.size) textColumn.start else textColumn.end, - textLine.lineBottom + relativeOffset, - textLine.lineTop + relativeOffset - ) + selectStartMoveIndex(textPos) } else { reverseStartCursor = true reverseEndCursor = false selectEnd.columnIndex++ selectStartMoveIndex(selectEnd) - selectEnd.upData(textPos) - upSelectedEnd( - if (textPos.columnIndex > -1) textColumn.end else textColumn.start, - textLine.lineBottom + relativeOffset - ) + selectEndMoveIndex(textPos) } - upSelectChars() } } @@ -301,29 +292,19 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at * 结束选择符移动 */ fun selectEndMove(x: Float, y: Float) { - touchRough(x, y) { relativeOffset, textPos, _, textLine, textColumn -> + touchRough(x, y) { _, textPos, _, _, _ -> if (textPos.compare(selectEnd) == 0) { return@touchRough } if (textPos.compare(selectStart) >= 0) { - selectEnd.upData(textPos) - upSelectedEnd( - if (textPos.columnIndex > -1) textColumn.end else textColumn.start, - textLine.lineBottom + relativeOffset - ) + selectEndMoveIndex(textPos) } else { reverseEndCursor = true reverseStartCursor = false selectStart.columnIndex-- selectEndMoveIndex(selectStart) - selectStart.upData(textPos) - upSelectedStart( - if (textPos.columnIndex < textLine.columns.size) textColumn.start else textColumn.end, - textLine.lineBottom + relativeOffset, - textLine.lineTop + relativeOffset - ) + selectStartMoveIndex(textPos) } - upSelectChars() } } @@ -494,7 +475,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at ) { selectStart.relativePagePos = relativePagePos selectStart.lineIndex = lineIndex - selectStart.columnIndex = charIndex + selectStart.columnIndex = max(0, charIndex) val textLine = relativePage(relativePagePos).getLine(lineIndex) val textColumn = textLine.getColumn(charIndex) upSelectedStart( @@ -519,8 +500,8 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at ) { selectEnd.relativePagePos = relativePage selectEnd.lineIndex = lineIndex - selectEnd.columnIndex = charIndex val textLine = relativePage(relativePage).getLine(lineIndex) + selectEnd.columnIndex = min(charIndex, textLine.columns.lastIndex) val textColumn = textLine.getColumn(charIndex) upSelectedEnd( if (charIndex > -1) textColumn.end else textColumn.start, @@ -549,12 +530,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at if (column is TextColumn) { val compareStart = textPos.compare(selectStart) val compareEnd = textPos.compare(selectEnd) - column.selected = when { - compareStart == 0 -> true - compareEnd == 0 -> true - compareStart > 0 && compareEnd < 0 -> true - else -> false - } + column.selected = compareStart >= 0 && compareEnd <= 0 column.isSearchResult = column.selected && callBack.isSelectingSearchResult if (column.isSearchResult) { @@ -620,28 +596,23 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at val compareEnd = textPos.compare(selectEnd) if (column is TextColumn) { when { - compareStart == 0 -> { - if (textPos.columnIndex < textLine.columns.size) { - builder.append(column.charData) - } - if ( - textLine.isParagraphEnd - && charIndex == textLine.columns.lastIndex - && compareEnd != 0 - ) { - builder.append("\n") - } + compareStart == -1 -> if ( + selectStart.columnIndex == textLine.columns.size + && charIndex == textLine.columns.lastIndex + ) { + builder.append("\n") } - compareEnd == 0 -> if (textPos.columnIndex > -1) { - builder.append(column.charData) + compareEnd == 1 -> if (selectEnd.columnIndex == -1 && charIndex == 0) { + builder.append("\n") } - compareStart > 0 && compareEnd < 0 -> { + compareStart >= 0 && compareEnd <= 0 -> { builder.append(column.charData) if ( textLine.isParagraphEnd && charIndex == textLine.columns.lastIndex + && compareEnd != 0 ) { builder.append("\n") }