@@ -278,17 +278,18 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
278
278
if (textPos.compare(selectEnd) <= 0 ) {
279
279
selectStart.upData(pos = textPos)
280
280
upSelectedStart(
281
- if (textPos.isTouch ) textColumn.start else textColumn.end,
281
+ if (textPos.columnIndex < textLine.columns.lastIndex ) textColumn.start else textColumn.end,
282
282
textLine.lineBottom + relativeOffset,
283
283
textLine.lineTop + relativeOffset
284
284
)
285
285
} else {
286
286
reverseStartCursor = true
287
287
reverseEndCursor = false
288
+ selectEnd.columnIndex++
288
289
selectStartMoveIndex(selectEnd)
289
290
selectEnd.upData(textPos)
290
291
upSelectedEnd(
291
- if (selectEnd.isTouch || selectEnd.isLast ) textColumn.end else textColumn.start,
292
+ if (textPos.columnIndex > - 1 ) textColumn.end else textColumn.start,
292
293
textLine.lineBottom + relativeOffset
293
294
)
294
295
}
@@ -307,16 +308,17 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
307
308
if (textPos.compare(selectStart) >= 0 ) {
308
309
selectEnd.upData(textPos)
309
310
upSelectedEnd(
310
- if (selectEnd.isTouch || selectEnd.isLast ) textColumn.end else textColumn.start,
311
+ if (textPos.columnIndex > - 1 ) textColumn.end else textColumn.start,
311
312
textLine.lineBottom + relativeOffset
312
313
)
313
314
} else {
314
315
reverseEndCursor = true
315
316
reverseStartCursor = false
317
+ selectStart.columnIndex--
316
318
selectEndMoveIndex(selectStart)
317
319
selectStart.upData(textPos)
318
320
upSelectedStart(
319
- if (textPos.isTouch ) textColumn.start else textColumn.end,
321
+ if (textPos.columnIndex < textLine.columns.lastIndex ) textColumn.start else textColumn.end,
320
322
textLine.lineBottom + relativeOffset,
321
323
textLine.lineTop + relativeOffset
322
324
)
@@ -418,11 +420,11 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
418
420
}
419
421
}
420
422
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
422
424
val textColumn = if (isLast) columns.last() else columns.first()
423
425
touched.invoke(
424
426
relativeOffset,
425
- TextPos (relativePos, lineIndex, charIndex, false , isLast ),
427
+ TextPos (relativePos, lineIndex, charIndex),
426
428
textPage, textLine, textColumn
427
429
)
428
430
return
@@ -489,26 +491,22 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
489
491
relativePagePos : Int ,
490
492
lineIndex : Int ,
491
493
charIndex : Int ,
492
- isTouch : Boolean ,
493
- isLast : Boolean = false
494
494
) {
495
495
selectStart.relativePagePos = relativePagePos
496
496
selectStart.lineIndex = lineIndex
497
497
selectStart.columnIndex = charIndex
498
- selectStart.isTouch = isTouch
499
- selectStart.isLast = isLast
500
498
val textLine = relativePage(relativePagePos).getLine(lineIndex)
501
499
val textColumn = textLine.getColumn(charIndex)
502
500
upSelectedStart(
503
- textColumn.start,
501
+ if (charIndex < textLine.columns.lastIndex) textColumn.start else textColumn.end ,
504
502
textLine.lineBottom + relativeOffset(relativePagePos),
505
503
textLine.lineTop + relativeOffset(relativePagePos)
506
504
)
507
505
upSelectChars()
508
506
}
509
507
510
508
fun selectStartMoveIndex (textPos : TextPos ) = textPos.run {
511
- selectStartMoveIndex(relativePagePos, lineIndex, columnIndex, isTouch, isLast )
509
+ selectStartMoveIndex(relativePagePos, lineIndex, columnIndex)
512
510
}
513
511
514
512
/* *
@@ -518,22 +516,21 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
518
516
relativePage : Int ,
519
517
lineIndex : Int ,
520
518
charIndex : Int ,
521
- isTouch : Boolean ,
522
- isLast : Boolean = false
523
519
) {
524
520
selectEnd.relativePagePos = relativePage
525
521
selectEnd.lineIndex = lineIndex
526
522
selectEnd.columnIndex = charIndex
527
- selectEnd.isTouch = isTouch
528
- selectEnd.isLast = isLast
529
523
val textLine = relativePage(relativePage).getLine(lineIndex)
530
524
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
+ )
532
529
upSelectChars()
533
530
}
534
531
535
532
fun selectEndMoveIndex (textPos : TextPos ) = textPos.run {
536
- selectEndMoveIndex(relativePagePos, lineIndex, columnIndex, isTouch, isLast )
533
+ selectEndMoveIndex(relativePagePos, lineIndex, columnIndex)
537
534
}
538
535
539
536
private fun upSelectChars () {
@@ -553,8 +550,8 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
553
550
val compareStart = textPos.compare(selectStart)
554
551
val compareEnd = textPos.compare(selectEnd)
555
552
column.selected = when {
556
- compareStart == 0 -> selectStart.isTouch
557
- compareEnd == 0 -> selectEnd.isTouch || selectEnd.isLast
553
+ compareStart == 0 -> true
554
+ compareEnd == 0 -> true
558
555
compareStart > 0 && compareEnd < 0 -> true
559
556
else -> false
560
557
}
@@ -624,27 +621,27 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
624
621
if (column is TextColumn ) {
625
622
when {
626
623
compareStart == 0 -> {
627
- if (selectStart.isTouch ) {
624
+ if (textPos.columnIndex < textLine.columns.lastIndex ) {
628
625
builder.append(column.charData)
629
626
}
630
627
if (
631
628
textLine.isParagraphEnd
632
- && charIndex == textLine.charSize - 1
629
+ && charIndex == textLine.columns.lastIndex
633
630
&& compareEnd != 0
634
631
) {
635
632
builder.append(" \n " )
636
633
}
637
634
}
638
635
639
- compareEnd == 0 -> if (selectEnd.isTouch || selectEnd.isLast ) {
636
+ compareEnd == 0 -> if (textPos.columnIndex > - 1 ) {
640
637
builder.append(column.charData)
641
638
}
642
639
643
640
compareStart > 0 && compareEnd < 0 -> {
644
641
builder.append(column.charData)
645
642
if (
646
643
textLine.isParagraphEnd
647
- && charIndex == textLine.charSize - 1
644
+ && charIndex == textLine.columns.lastIndex
648
645
) {
649
646
builder.append(" \n " )
650
647
}
0 commit comments