@@ -98,6 +98,10 @@ class QuillTextManager(quillSpan: QuillSpan) {
98
98
getRichSpanListByTextRange(selection).distinct()
99
99
}
100
100
101
+ updateSpanStyle(currentStyles)
102
+ }
103
+
104
+ private fun updateSpanStyle (currentStyles : List <TextSpanStyle >) {
101
105
val currentSpan = quillTextSpans.findLast {
102
106
it.from <= selection.min - 2 && it.to >= selection.min - 2 && it.style.contains(
103
107
TextSpanStyle .BulletStyle
@@ -395,48 +399,60 @@ class QuillTextManager(quillSpan: QuillSpan) {
395
399
when {
396
400
span.style == selectedStyles -> {
397
401
if (isBulletStyle && newValue.getOrNull(startTypeIndex) == ' \n ' ) {
398
- if (newValue.getOrNull(startTypeIndex - 1 ) != ' \n ' && startTypeIndex == to) {
399
- quillTextSpans.add(
400
- index + 1 ,
401
- span.copy(
402
- from = startTypeIndex,
403
- to = startTypeIndex + typedCharsCount - 1 ,
404
- style = selectedStyles
405
- )
406
- )
407
- quillTextSpans.add(
408
- index + 2 ,
409
- span.copy(
410
- from = startTypeIndex + typedCharsCount,
411
- to = to + typedCharsCount,
412
- style = selectedStyles
413
- )
414
- )
415
- } else {
416
- if (startTypeIndex in (from + 1 ) until to) {
417
- val newSpans = mutableListOf<QuillTextSpan >()
418
- newSpans.add(span.copy(to = startTypeIndex - 1 , style = styles))
419
- newSpans.add(
420
- span.copy(
421
- from = startTypeIndex,
422
- to = startTypeIndex + typedCharsCount - 1 ,
423
- style = selectedStyles
402
+ if (newValue.getOrNull(startTypeIndex - 1 ) != ' \n ' ) {
403
+ when (startTypeIndex) {
404
+ to -> {
405
+ quillTextSpans.add(
406
+ index + 1 ,
407
+ span.copy(
408
+ from = startTypeIndex,
409
+ to = startTypeIndex + typedCharsCount - 1 ,
410
+ style = selectedStyles
411
+ )
424
412
)
425
- )
426
- newSpans.add(
427
- span.copy(
428
- from = startTypeIndex + typedCharsCount,
429
- to = to + typedCharsCount,
430
- style = styles
413
+ quillTextSpans.add(
414
+ index + 2 ,
415
+ span.copy(
416
+ from = startTypeIndex + typedCharsCount,
417
+ to = to + typedCharsCount,
418
+ style = selectedStyles
419
+ )
431
420
)
432
- )
433
- quillTextSpans.removeAt(index)
434
- quillTextSpans.addAll(index, newSpans)
435
- } else {
436
- val updatedSpan = span.copy(to = to + typedCharsCount, style = selectedStyles)
437
- quillTextSpans[index] = updatedSpan
438
- quillTextSpans.add(index + 1 , updatedSpan)
421
+ }
422
+
423
+ in (from + 1 ) until to -> {
424
+ val newSpans = mutableListOf<QuillTextSpan >()
425
+ newSpans.add(span.copy(to = startTypeIndex - 1 , style = styles))
426
+ newSpans.add(
427
+ span.copy(
428
+ from = startTypeIndex,
429
+ to = startTypeIndex + typedCharsCount - 1 ,
430
+ style = selectedStyles
431
+ )
432
+ )
433
+ newSpans.add(
434
+ span.copy(
435
+ from = startTypeIndex + typedCharsCount,
436
+ to = to + typedCharsCount,
437
+ style = styles
438
+ )
439
+ )
440
+ quillTextSpans.removeAt(index)
441
+ quillTextSpans.addAll(index, newSpans)
442
+ }
443
+
444
+ else -> {
445
+ val updatedSpan =
446
+ span.copy(to = to + typedCharsCount, style = selectedStyles)
447
+ quillTextSpans[index] = updatedSpan
448
+ quillTextSpans.add(index + 1 , updatedSpan)
449
+ }
439
450
}
451
+ } else {
452
+ quillTextSpans[index] =
453
+ span.copy(to = to + typedCharsCount, style = styles.filterNot {
454
+ it == TextSpanStyle .BulletStyle
455
+ })
440
456
}
441
457
} else {
442
458
quillTextSpans[index] = span.copy(to = to + typedCharsCount, style = styles)
0 commit comments