diff --git a/editor/src/main/java/com/canopas/editor/ui/data/QuillTextManager.kt b/editor/src/main/java/com/canopas/editor/ui/data/QuillTextManager.kt index f91bcdb..deb4613 100644 --- a/editor/src/main/java/com/canopas/editor/ui/data/QuillTextManager.kt +++ b/editor/src/main/java/com/canopas/editor/ui/data/QuillTextManager.kt @@ -266,21 +266,14 @@ class QuillTextManager(quillSpan: QuillSpan) { val fromIndex = selection.min val toIndex = if (selection.collapsed) fromIndex else selection.max - val startIndex: Int = max(0, text.lastIndexOf("\n", fromIndex - 1)) - var endIndex: Int = text.indexOf("\n", toIndex) - - if (endIndex == -1) endIndex = text.length - 1 - val selectedParts = - quillTextSpans.filter { endIndex >= it.to && startIndex <= it.from && it.style.any { it.isHeaderStyle() } } - - quillTextSpans.removeAll(selectedParts) - quillTextSpans.add( - QuillTextSpan( - from = startIndex, - to = endIndex, - style = listOf(style) - ) - ) + val currentSpan = quillTextSpans.find { + it.from <= fromIndex && it.to >= toIndex + } + val index = quillTextSpans.indexOf(currentSpan) + quillTextSpans[index] = + currentSpan?.copy(style = currentSpan.style.filterNot { it.isHeaderStyle() } + listOf( + style + )) ?: return updateText() } @@ -308,7 +301,9 @@ class QuillTextManager(quillSpan: QuillSpan) { part.from < endIndex && part.to >= startIndex } - quillTextSpans.removeAll(selectedParts.filter { it.style.any { it.isHeaderStyle() } }) + quillTextSpans.removeAll(selectedParts.filter { + it.style.size == 1 && it.style.first().isHeaderStyle() + }) } private fun removeStylesFromSelectedPart(