From 9639a10be430cf41193337fba8571365b8b08038 Mon Sep 17 00:00:00 2001 From: Gerardo Date: Mon, 22 Jan 2024 19:28:02 +0100 Subject: [PATCH] Update updating existing MarkSpan logic --- .../aztec/formatting/InlineFormatter.kt | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/aztec/src/main/kotlin/org/wordpress/aztec/formatting/InlineFormatter.kt b/aztec/src/main/kotlin/org/wordpress/aztec/formatting/InlineFormatter.kt index c1fa85b31..b0705ab05 100644 --- a/aztec/src/main/kotlin/org/wordpress/aztec/formatting/InlineFormatter.kt +++ b/aztec/src/main/kotlin/org/wordpress/aztec/formatting/InlineFormatter.kt @@ -109,6 +109,7 @@ class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle, private val h } AztecTextFormat.FORMAT_MARK -> { applyInlineStyle(item, textChangedEvent.inputStart, textChangedEvent.inputEnd) + applyAfterMarkInlineStyle(textChangedEvent.inputStart, textChangedEvent.inputEnd) } else -> { // do nothing @@ -246,27 +247,32 @@ class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle, private val h } } - public fun updateMarkStyle(start: Int = selectionStart, end: Int = selectionEnd) { + private fun applyAfterMarkInlineStyle(start: Int = selectionStart, end: Int = selectionEnd) { + // If there's no new mark style color to update, it skips applying the style updates. + if (markStyleColor == null) { + return + } + val spans = editableText.getSpans(start, end, MarkSpan::class.java) spans.forEach { span -> if (span != null) { - val currentSpanStart = editableText.getSpanStart(span) - val currentSpanEnd = editableText.getSpanEnd(span) val color = span.getTextColor() + val currentSpanStart = editableText.getSpanStart(span) editableText.removeSpan(span) editableText.setSpan( MarkSpan(AztecAttributes(), color), currentSpanStart, - currentSpanEnd, + start, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE ) editableText.setSpan( MarkSpan(AztecAttributes(), markStyleColor), start, end, - Spanned.SPAN_INCLUSIVE_INCLUSIVE + Spanned.SPAN_EXCLUSIVE_EXCLUSIVE ) + markStyleColor = null; } } }