@@ -55,7 +55,7 @@ class QuillTextManager(quillSpan: QuillSpan) {
55
55
get() = editable.toString()
56
56
57
57
private var selection = TextRange (0 , 0 )
58
- private val currentStyles = mutableStateListOf<TextSpanStyle >()
58
+ internal val currentStyles = mutableStateListOf<TextSpanStyle >()
59
59
private var rawText: String = editableText
60
60
61
61
internal fun setEditable (editable : Editable ) {
@@ -364,12 +364,19 @@ class QuillTextManager(quillSpan: QuillSpan) {
364
364
this .rawText = newText.toString()
365
365
}
366
366
367
- private fun handleAddingCharacters (newValue : Editable ) {
367
+ internal fun handleAddingCharacters (newValue : Editable ) {
368
368
val typedCharsCount = newValue.length - rawText.length
369
369
val startTypeIndex = selection.min - typedCharsCount
370
370
371
371
if (newValue.getOrNull(startTypeIndex) == ' \n ' && currentStyles.any { it.isHeaderStyle() }) {
372
372
currentStyles.clear()
373
+ quillTextSpans.find { it.from <= startTypeIndex && it.to >= startTypeIndex }
374
+ ?.let { span ->
375
+ val index = quillTextSpans.indexOf(span)
376
+ val styles = span.style.filterNot { it.isHeaderStyle() }
377
+ val updatedSpan = span.copy(style = styles)
378
+ quillTextSpans[index] = updatedSpan
379
+ }
373
380
}
374
381
375
382
val selectedStyles = currentStyles.distinct()
@@ -388,7 +395,7 @@ class QuillTextManager(quillSpan: QuillSpan) {
388
395
when {
389
396
span.style == selectedStyles -> {
390
397
if (isBulletStyle && newValue.getOrNull(startTypeIndex) == ' \n ' ) {
391
- if (newValue.getOrNull(startTypeIndex - 1 ) != ' \n ' ) {
398
+ if (newValue.getOrNull(startTypeIndex - 1 ) != ' \n ' && startTypeIndex == to ) {
392
399
quillTextSpans.add(
393
400
index + 1 ,
394
401
span.copy(
@@ -406,11 +413,30 @@ class QuillTextManager(quillSpan: QuillSpan) {
406
413
)
407
414
)
408
415
} else {
409
- val updatedSpan = span.copy(to = to + typedCharsCount,
410
- style = selectedStyles.filterNot { it == TextSpanStyle .BulletStyle }
411
- )
412
- quillTextSpans[index - 1 ] = updatedSpan
413
- quillTextSpans[index] = updatedSpan
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
424
+ )
425
+ )
426
+ newSpans.add(
427
+ span.copy(
428
+ from = startTypeIndex + typedCharsCount,
429
+ to = to + typedCharsCount,
430
+ style = styles
431
+ )
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)
439
+ }
414
440
}
415
441
} else {
416
442
quillTextSpans[index] = span.copy(to = to + typedCharsCount, style = styles)
0 commit comments