Skip to content

Commit b562c3a

Browse files
authored
Merge branch 'gedoor:master' into main
2 parents 1b40144 + 27571f5 commit b562c3a

File tree

4 files changed

+31
-56
lines changed

4 files changed

+31
-56
lines changed

app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt

+21-24
Original file line numberDiff line numberDiff line change
@@ -278,17 +278,18 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
278278
if (textPos.compare(selectEnd) <= 0) {
279279
selectStart.upData(pos = textPos)
280280
upSelectedStart(
281-
if (textPos.isTouch) textColumn.start else textColumn.end,
281+
if (textPos.columnIndex < textLine.columns.lastIndex) textColumn.start else textColumn.end,
282282
textLine.lineBottom + relativeOffset,
283283
textLine.lineTop + relativeOffset
284284
)
285285
} else {
286286
reverseStartCursor = true
287287
reverseEndCursor = false
288+
selectEnd.columnIndex++
288289
selectStartMoveIndex(selectEnd)
289290
selectEnd.upData(textPos)
290291
upSelectedEnd(
291-
if (selectEnd.isTouch || selectEnd.isLast) textColumn.end else textColumn.start,
292+
if (textPos.columnIndex > -1) textColumn.end else textColumn.start,
292293
textLine.lineBottom + relativeOffset
293294
)
294295
}
@@ -307,16 +308,17 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
307308
if (textPos.compare(selectStart) >= 0) {
308309
selectEnd.upData(textPos)
309310
upSelectedEnd(
310-
if (selectEnd.isTouch || selectEnd.isLast) textColumn.end else textColumn.start,
311+
if (textPos.columnIndex > -1) textColumn.end else textColumn.start,
311312
textLine.lineBottom + relativeOffset
312313
)
313314
} else {
314315
reverseEndCursor = true
315316
reverseStartCursor = false
317+
selectStart.columnIndex--
316318
selectEndMoveIndex(selectStart)
317319
selectStart.upData(textPos)
318320
upSelectedStart(
319-
if (textPos.isTouch) textColumn.start else textColumn.end,
321+
if (textPos.columnIndex < textLine.columns.lastIndex) textColumn.start else textColumn.end,
320322
textLine.lineBottom + relativeOffset,
321323
textLine.lineTop + relativeOffset
322324
)
@@ -418,11 +420,11 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
418420
}
419421
}
420422
val isLast = columns.first().start < x
421-
val charIndex = if (isLast) columns.lastIndex else 0
423+
val charIndex = if (isLast) columns.lastIndex + 1 else -1
422424
val textColumn = if (isLast) columns.last() else columns.first()
423425
touched.invoke(
424426
relativeOffset,
425-
TextPos(relativePos, lineIndex, charIndex, false, isLast),
427+
TextPos(relativePos, lineIndex, charIndex),
426428
textPage, textLine, textColumn
427429
)
428430
return
@@ -489,26 +491,22 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
489491
relativePagePos: Int,
490492
lineIndex: Int,
491493
charIndex: Int,
492-
isTouch: Boolean,
493-
isLast: Boolean = false
494494
) {
495495
selectStart.relativePagePos = relativePagePos
496496
selectStart.lineIndex = lineIndex
497497
selectStart.columnIndex = charIndex
498-
selectStart.isTouch = isTouch
499-
selectStart.isLast = isLast
500498
val textLine = relativePage(relativePagePos).getLine(lineIndex)
501499
val textColumn = textLine.getColumn(charIndex)
502500
upSelectedStart(
503-
textColumn.start,
501+
if (charIndex < textLine.columns.lastIndex) textColumn.start else textColumn.end,
504502
textLine.lineBottom + relativeOffset(relativePagePos),
505503
textLine.lineTop + relativeOffset(relativePagePos)
506504
)
507505
upSelectChars()
508506
}
509507

510508
fun selectStartMoveIndex(textPos: TextPos) = textPos.run {
511-
selectStartMoveIndex(relativePagePos, lineIndex, columnIndex, isTouch, isLast)
509+
selectStartMoveIndex(relativePagePos, lineIndex, columnIndex)
512510
}
513511

514512
/**
@@ -518,22 +516,21 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
518516
relativePage: Int,
519517
lineIndex: Int,
520518
charIndex: Int,
521-
isTouch: Boolean,
522-
isLast: Boolean = false
523519
) {
524520
selectEnd.relativePagePos = relativePage
525521
selectEnd.lineIndex = lineIndex
526522
selectEnd.columnIndex = charIndex
527-
selectEnd.isTouch = isTouch
528-
selectEnd.isLast = isLast
529523
val textLine = relativePage(relativePage).getLine(lineIndex)
530524
val textColumn = textLine.getColumn(charIndex)
531-
upSelectedEnd(textColumn.end, textLine.lineBottom + relativeOffset(relativePage))
525+
upSelectedEnd(
526+
if (charIndex > -1) textColumn.end else textColumn.start,
527+
textLine.lineBottom + relativeOffset(relativePage)
528+
)
532529
upSelectChars()
533530
}
534531

535532
fun selectEndMoveIndex(textPos: TextPos) = textPos.run {
536-
selectEndMoveIndex(relativePagePos, lineIndex, columnIndex, isTouch, isLast)
533+
selectEndMoveIndex(relativePagePos, lineIndex, columnIndex)
537534
}
538535

539536
private fun upSelectChars() {
@@ -553,8 +550,8 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
553550
val compareStart = textPos.compare(selectStart)
554551
val compareEnd = textPos.compare(selectEnd)
555552
column.selected = when {
556-
compareStart == 0 -> selectStart.isTouch
557-
compareEnd == 0 -> selectEnd.isTouch || selectEnd.isLast
553+
compareStart == 0 -> true
554+
compareEnd == 0 -> true
558555
compareStart > 0 && compareEnd < 0 -> true
559556
else -> false
560557
}
@@ -624,27 +621,27 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
624621
if (column is TextColumn) {
625622
when {
626623
compareStart == 0 -> {
627-
if (selectStart.isTouch) {
624+
if (textPos.columnIndex < textLine.columns.lastIndex) {
628625
builder.append(column.charData)
629626
}
630627
if (
631628
textLine.isParagraphEnd
632-
&& charIndex == textLine.charSize - 1
629+
&& charIndex == textLine.columns.lastIndex
633630
&& compareEnd != 0
634631
) {
635632
builder.append("\n")
636633
}
637634
}
638635

639-
compareEnd == 0 -> if (selectEnd.isTouch || selectEnd.isLast) {
636+
compareEnd == 0 -> if (textPos.columnIndex > -1) {
640637
builder.append(column.charData)
641638
}
642639

643640
compareStart > 0 && compareEnd < 0 -> {
644641
builder.append(column.charData)
645642
if (
646643
textLine.isParagraphEnd
647-
&& charIndex == textLine.charSize - 1
644+
&& charIndex == textLine.columns.lastIndex
648645
) {
649646
builder.append("\n")
650647
}

app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt

+4-20
Original file line numberDiff line numberDiff line change
@@ -404,17 +404,9 @@ class PageView(context: Context) : FrameLayout(context) {
404404
fun selectStartMoveIndex(
405405
relativePagePos: Int,
406406
lineIndex: Int,
407-
charIndex: Int,
408-
isTouch: Boolean = true,
409-
isLast: Boolean = false
407+
charIndex: Int
410408
) {
411-
binding.contentTextView.selectStartMoveIndex(
412-
relativePagePos,
413-
lineIndex,
414-
charIndex,
415-
isTouch,
416-
isLast
417-
)
409+
binding.contentTextView.selectStartMoveIndex(relativePagePos, lineIndex, charIndex)
418410
}
419411

420412
fun selectStartMoveIndex(textPos: TextPos) {
@@ -428,17 +420,9 @@ class PageView(context: Context) : FrameLayout(context) {
428420
fun selectEndMoveIndex(
429421
relativePagePos: Int,
430422
lineIndex: Int,
431-
charIndex: Int,
432-
isTouch: Boolean = true,
433-
isLast: Boolean = false
423+
charIndex: Int
434424
) {
435-
binding.contentTextView.selectEndMoveIndex(
436-
relativePagePos,
437-
lineIndex,
438-
charIndex,
439-
isTouch,
440-
isLast
441-
)
425+
binding.contentTextView.selectEndMoveIndex(relativePagePos, lineIndex, charIndex)
442426
}
443427

444428
fun selectEndMoveIndex(textPos: TextPos) {

app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt

+6-2
Original file line numberDiff line numberDiff line change
@@ -443,9 +443,13 @@ class ReadView(context: Context, attrs: AttributeSet) :
443443
curPage.selectText(x, y) { textPos ->
444444
val compare = initialTextPos.compare(textPos)
445445
when {
446-
compare >= 0 -> {
446+
compare > 0 -> {
447447
curPage.selectStartMoveIndex(textPos)
448-
curPage.selectEndMoveIndex(initialTextPos)
448+
curPage.selectEndMoveIndex(
449+
initialTextPos.relativePagePos,
450+
initialTextPos.lineIndex,
451+
initialTextPos.columnIndex - 1
452+
)
449453
}
450454

451455
else -> {

app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPos.kt

-10
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,22 @@ data class TextPos(
1111
var relativePagePos: Int,
1212
var lineIndex: Int,
1313
var columnIndex: Int,
14-
var isTouch: Boolean = true,
15-
var isLast: Boolean = false
1614
) {
1715

1816
fun upData(
1917
relativePos: Int,
2018
lineIndex: Int,
2119
charIndex: Int,
22-
isTouch: Boolean,
23-
isLast: Boolean
2420
) {
2521
this.relativePagePos = relativePos
2622
this.lineIndex = lineIndex
2723
this.columnIndex = charIndex
28-
this.isTouch = isTouch
29-
this.isLast = isLast
3024
}
3125

3226
fun upData(pos: TextPos) {
3327
relativePagePos = pos.relativePagePos
3428
lineIndex = pos.lineIndex
3529
columnIndex = pos.columnIndex
36-
isTouch = pos.isTouch
37-
isLast = pos.isLast
3830
}
3931

4032
fun compare(pos: TextPos): Int {
@@ -65,8 +57,6 @@ data class TextPos(
6557
relativePagePos = 0
6658
lineIndex = -1
6759
columnIndex = -1
68-
isTouch = true
69-
isLast = false
7060
}
7161

7262
fun isSelected(): Boolean {

0 commit comments

Comments
 (0)