This commit is contained in:
Horis
2024-07-14 21:36:13 +08:00
parent 1a98536f7e
commit 4ee03e7ccf
@@ -27,6 +27,7 @@ import io.legado.app.utils.getCompatColor
import io.legado.app.utils.showDialogFragment import io.legado.app.utils.showDialogFragment
import io.legado.app.utils.toastOnUi import io.legado.app.utils.toastOnUi
import java.util.concurrent.Executors import java.util.concurrent.Executors
import kotlin.math.max
import kotlin.math.min import kotlin.math.min
/** /**
@@ -271,29 +272,19 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
* 开始选择符移动 * 开始选择符移动
*/ */
fun selectStartMove(x: Float, y: Float) { fun selectStartMove(x: Float, y: Float) {
touchRough(x, y) { relativeOffset, textPos, _, textLine, textColumn -> touchRough(x, y) { _, textPos, _, _, _ ->
if (selectStart.compare(textPos) == 0) { if (selectStart.compare(textPos) == 0) {
return@touchRough return@touchRough
} }
if (textPos.compare(selectEnd) <= 0) { if (textPos.compare(selectEnd) <= 0) {
selectStart.upData(pos = textPos) selectStartMoveIndex(textPos)
upSelectedStart(
if (textPos.columnIndex < textLine.columns.size) textColumn.start else textColumn.end,
textLine.lineBottom + relativeOffset,
textLine.lineTop + relativeOffset
)
} else { } else {
reverseStartCursor = true reverseStartCursor = true
reverseEndCursor = false reverseEndCursor = false
selectEnd.columnIndex++ selectEnd.columnIndex++
selectStartMoveIndex(selectEnd) selectStartMoveIndex(selectEnd)
selectEnd.upData(textPos) selectEndMoveIndex(textPos)
upSelectedEnd(
if (textPos.columnIndex > -1) textColumn.end else textColumn.start,
textLine.lineBottom + relativeOffset
)
} }
upSelectChars()
} }
} }
@@ -301,29 +292,19 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
* 结束选择符移动 * 结束选择符移动
*/ */
fun selectEndMove(x: Float, y: Float) { fun selectEndMove(x: Float, y: Float) {
touchRough(x, y) { relativeOffset, textPos, _, textLine, textColumn -> touchRough(x, y) { _, textPos, _, _, _ ->
if (textPos.compare(selectEnd) == 0) { if (textPos.compare(selectEnd) == 0) {
return@touchRough return@touchRough
} }
if (textPos.compare(selectStart) >= 0) { if (textPos.compare(selectStart) >= 0) {
selectEnd.upData(textPos) selectEndMoveIndex(textPos)
upSelectedEnd(
if (textPos.columnIndex > -1) textColumn.end else textColumn.start,
textLine.lineBottom + relativeOffset
)
} else { } else {
reverseEndCursor = true reverseEndCursor = true
reverseStartCursor = false reverseStartCursor = false
selectStart.columnIndex-- selectStart.columnIndex--
selectEndMoveIndex(selectStart) selectEndMoveIndex(selectStart)
selectStart.upData(textPos) selectStartMoveIndex(textPos)
upSelectedStart(
if (textPos.columnIndex < textLine.columns.size) textColumn.start else textColumn.end,
textLine.lineBottom + relativeOffset,
textLine.lineTop + relativeOffset
)
} }
upSelectChars()
} }
} }
@@ -494,7 +475,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
) { ) {
selectStart.relativePagePos = relativePagePos selectStart.relativePagePos = relativePagePos
selectStart.lineIndex = lineIndex selectStart.lineIndex = lineIndex
selectStart.columnIndex = charIndex selectStart.columnIndex = max(0, charIndex)
val textLine = relativePage(relativePagePos).getLine(lineIndex) val textLine = relativePage(relativePagePos).getLine(lineIndex)
val textColumn = textLine.getColumn(charIndex) val textColumn = textLine.getColumn(charIndex)
upSelectedStart( upSelectedStart(
@@ -519,8 +500,8 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
) { ) {
selectEnd.relativePagePos = relativePage selectEnd.relativePagePos = relativePage
selectEnd.lineIndex = lineIndex selectEnd.lineIndex = lineIndex
selectEnd.columnIndex = charIndex
val textLine = relativePage(relativePage).getLine(lineIndex) val textLine = relativePage(relativePage).getLine(lineIndex)
selectEnd.columnIndex = min(charIndex, textLine.columns.lastIndex)
val textColumn = textLine.getColumn(charIndex) val textColumn = textLine.getColumn(charIndex)
upSelectedEnd( upSelectedEnd(
if (charIndex > -1) textColumn.end else textColumn.start, 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) { if (column is TextColumn) {
val compareStart = textPos.compare(selectStart) val compareStart = textPos.compare(selectStart)
val compareEnd = textPos.compare(selectEnd) val compareEnd = textPos.compare(selectEnd)
column.selected = when { column.selected = compareStart >= 0 && compareEnd <= 0
compareStart == 0 -> true
compareEnd == 0 -> true
compareStart > 0 && compareEnd < 0 -> true
else -> false
}
column.isSearchResult = column.isSearchResult =
column.selected && callBack.isSelectingSearchResult column.selected && callBack.isSelectingSearchResult
if (column.isSearchResult) { if (column.isSearchResult) {
@@ -620,10 +596,19 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
val compareEnd = textPos.compare(selectEnd) val compareEnd = textPos.compare(selectEnd)
if (column is TextColumn) { if (column is TextColumn) {
when { when {
compareStart == 0 -> { compareStart == -1 -> if (
if (textPos.columnIndex < textLine.columns.size) { selectStart.columnIndex == textLine.columns.size
builder.append(column.charData) && charIndex == textLine.columns.lastIndex
} ) {
builder.append("\n")
}
compareEnd == 1 -> if (selectEnd.columnIndex == -1 && charIndex == 0) {
builder.append("\n")
}
compareStart >= 0 && compareEnd <= 0 -> {
builder.append(column.charData)
if ( if (
textLine.isParagraphEnd textLine.isParagraphEnd
&& charIndex == textLine.columns.lastIndex && charIndex == textLine.columns.lastIndex
@@ -632,20 +617,6 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
builder.append("\n") builder.append("\n")
} }
} }
compareEnd == 0 -> if (textPos.columnIndex > -1) {
builder.append(column.charData)
}
compareStart > 0 && compareEnd < 0 -> {
builder.append(column.charData)
if (
textLine.isParagraphEnd
&& charIndex == textLine.columns.lastIndex
) {
builder.append("\n")
}
}
} }
} }
} }