From 13c580a785c6ac4147759ba437f9beb730b069cd Mon Sep 17 00:00:00 2001 From: Gerardo Date: Fri, 19 Jan 2024 13:18:47 +0100 Subject: [PATCH 01/12] Improve Mark formating by implementing custom Mark plugin and supporting color customization --- .../kotlin/org/wordpress/aztec/AztecText.kt | 1 + .../aztec/formatting/InlineFormatter.kt | 36 +++++++++++++------ .../org/wordpress/aztec/plugins/MarkPlugin.kt | 25 +++++++++++++ .../org/wordpress/aztec/spans/MarkSpan.kt | 32 +++++++++++++++-- 4 files changed, 81 insertions(+), 13 deletions(-) create mode 100644 aztec/src/main/kotlin/org/wordpress/aztec/plugins/MarkPlugin.kt diff --git a/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt b/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt index a5d97bfec..3ac7ac57e 100644 --- a/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt +++ b/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt @@ -1344,6 +1344,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown AztecTextFormat.FORMAT_CODE -> inlineFormatter.toggle(textFormat) AztecTextFormat.FORMAT_BOLD, AztecTextFormat.FORMAT_STRONG -> inlineFormatter.toggleAny(ToolbarAction.BOLD.textFormats) + AztecTextFormat.FORMAT_MARK -> inlineFormatter.toggle(textFormat) AztecTextFormat.FORMAT_UNORDERED_LIST -> blockFormatter.toggleUnorderedList() AztecTextFormat.FORMAT_TASK_LIST -> blockFormatter.toggleTaskList() AztecTextFormat.FORMAT_ORDERED_LIST -> blockFormatter.toggleOrderedList() 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 287ed33e5..c1fa85b31 100644 --- a/aztec/src/main/kotlin/org/wordpress/aztec/formatting/InlineFormatter.kt +++ b/aztec/src/main/kotlin/org/wordpress/aztec/formatting/InlineFormatter.kt @@ -40,6 +40,7 @@ class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle, private val h data class CodeStyle(val codeBackground: Int, val codeBackgroundAlpha: Float, val codeColor: Int) data class HighlightStyle(@ColorRes val color: Int) + var markStyleColor: String? = null fun toggle(textFormat: ITextFormat) { if (!containsInlineStyle(textFormat)) { @@ -107,12 +108,7 @@ class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle, private val h applyInlineStyle(item, textChangedEvent.inputStart, textChangedEvent.inputEnd) } AztecTextFormat.FORMAT_MARK -> { - // For cases of an empty mark tag, either at the beginning of the text or in between - if (textChangedEvent.inputStart == 0 && textChangedEvent.inputEnd == 1) { - applyMarkInlineStyle(textChangedEvent.inputStart, textChangedEvent.inputEnd) - } else { - applyInlineStyle(item, textChangedEvent.inputStart, textChangedEvent.inputEnd) - } + applyInlineStyle(item, textChangedEvent.inputStart, textChangedEvent.inputEnd) } else -> { // do nothing @@ -250,10 +246,28 @@ class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle, private val h } } - private fun applyMarkInlineStyle(start: Int = selectionStart, end: Int = selectionEnd) { - val previousSpans = editableText.getSpans(start, end, MarkSpan::class.java) - previousSpans.forEach { - it.applyInlineStyleAttributes(editableText, start, end) + public fun updateMarkStyle(start: Int = selectionStart, end: Int = selectionEnd) { + 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() + + editableText.removeSpan(span) + editableText.setSpan( + MarkSpan(AztecAttributes(), color), + currentSpanStart, + currentSpanEnd, + Spanned.SPAN_EXCLUSIVE_EXCLUSIVE + ) + editableText.setSpan( + MarkSpan(AztecAttributes(), markStyleColor), + start, + end, + Spanned.SPAN_INCLUSIVE_INCLUSIVE + ) + } } } @@ -444,7 +458,7 @@ class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle, private val h AztecTextFormat.FORMAT_HIGHLIGHT -> { HighlightSpan.create(context = editor.context, defaultStyle = highlightStyle) } - AztecTextFormat.FORMAT_MARK -> MarkSpan() + AztecTextFormat.FORMAT_MARK -> MarkSpan(AztecAttributes(), markStyleColor) else -> AztecStyleSpan(Typeface.NORMAL) } } diff --git a/aztec/src/main/kotlin/org/wordpress/aztec/plugins/MarkPlugin.kt b/aztec/src/main/kotlin/org/wordpress/aztec/plugins/MarkPlugin.kt new file mode 100644 index 000000000..e3320e1ef --- /dev/null +++ b/aztec/src/main/kotlin/org/wordpress/aztec/plugins/MarkPlugin.kt @@ -0,0 +1,25 @@ +package org.wordpress.aztec.plugins + +import android.text.SpannableStringBuilder +import org.wordpress.aztec.plugins.visual2html.ISpanPreprocessor +import org.wordpress.aztec.source.CssStyleFormatter +import org.wordpress.aztec.spans.MarkSpan + +class MarkPlugin : ISpanPreprocessor { + + override fun beforeSpansProcessed(spannable: SpannableStringBuilder) { + spannable.getSpans(0, spannable.length, MarkSpan::class.java).forEach { + if (!CssStyleFormatter.containsStyleAttribute(it.attributes, CssStyleFormatter.CSS_BACKGROUND_COLOR_ATTRIBUTE)) { + CssStyleFormatter.addStyleAttribute(it.attributes, CssStyleFormatter.CSS_BACKGROUND_COLOR_ATTRIBUTE, "rgba(0, 0, 0, 0)") + } + + if (!CssStyleFormatter.containsStyleAttribute(it.attributes, CssStyleFormatter.CSS_COLOR_ATTRIBUTE)) { + CssStyleFormatter.addStyleAttribute(it.attributes, CssStyleFormatter.CSS_COLOR_ATTRIBUTE, it.getTextColor()) + } + + if (!it.attributes.hasAttribute("class")) { + it.attributes.setValue("class", "has-inline-color") + } + } + } +} diff --git a/aztec/src/main/kotlin/org/wordpress/aztec/spans/MarkSpan.kt b/aztec/src/main/kotlin/org/wordpress/aztec/spans/MarkSpan.kt index 8ab898b3b..11f963bc5 100644 --- a/aztec/src/main/kotlin/org/wordpress/aztec/spans/MarkSpan.kt +++ b/aztec/src/main/kotlin/org/wordpress/aztec/spans/MarkSpan.kt @@ -1,12 +1,40 @@ package org.wordpress.aztec.spans +import android.graphics.Color import android.text.TextPaint import android.text.style.CharacterStyle import org.wordpress.aztec.AztecAttributes -class MarkSpan(override var attributes: AztecAttributes = AztecAttributes()) : CharacterStyle(), IAztecInlineSpan { + +class MarkSpan : CharacterStyle, IAztecInlineSpan { override var TAG = "mark" - override fun updateDrawState(tp: TextPaint?) { + override var attributes: AztecAttributes = AztecAttributes() + var textColor: Int? = null + + constructor(attributes: AztecAttributes = AztecAttributes()) : super() { + this.attributes = attributes + } + + constructor(attributes: AztecAttributes = AztecAttributes(), colorString: String?) : super() { + this.attributes = attributes + + if (colorString != null) { + textColor = Color.parseColor(colorString) + } + } + + override fun updateDrawState(tp: TextPaint) { + configureTextPaint(tp) + } + + private fun configureTextPaint(tp: TextPaint) { + if (textColor != null) { + tp.color = textColor as Int + } + } + + fun getTextColor(): String { + return java.lang.String.format("#%06X", 0xFFFFFF and textColor!!); } } From 4f79f246daa17f0be0eed60a890033c73da41f7f Mon Sep 17 00:00:00 2001 From: Gerardo Date: Fri, 19 Jan 2024 14:49:37 +0100 Subject: [PATCH 02/12] Fix lint issues --- aztec/src/main/kotlin/org/wordpress/aztec/spans/MarkSpan.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/aztec/src/main/kotlin/org/wordpress/aztec/spans/MarkSpan.kt b/aztec/src/main/kotlin/org/wordpress/aztec/spans/MarkSpan.kt index 11f963bc5..1b127c8cc 100644 --- a/aztec/src/main/kotlin/org/wordpress/aztec/spans/MarkSpan.kt +++ b/aztec/src/main/kotlin/org/wordpress/aztec/spans/MarkSpan.kt @@ -5,7 +5,6 @@ import android.text.TextPaint import android.text.style.CharacterStyle import org.wordpress.aztec.AztecAttributes - class MarkSpan : CharacterStyle, IAztecInlineSpan { override var TAG = "mark" @@ -35,6 +34,6 @@ class MarkSpan : CharacterStyle, IAztecInlineSpan { } fun getTextColor(): String { - return java.lang.String.format("#%06X", 0xFFFFFF and textColor!!); + return java.lang.String.format("#%06X", 0xFFFFFF and textColor!!) } } From c48c233ec782da8dadabe9e81f8c480af2fa6d6d Mon Sep 17 00:00:00 2001 From: Gerardo Date: Mon, 22 Jan 2024 19:27:35 +0100 Subject: [PATCH 03/12] Fix getTextColor in MarkSpan --- aztec/src/main/kotlin/org/wordpress/aztec/spans/MarkSpan.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/aztec/src/main/kotlin/org/wordpress/aztec/spans/MarkSpan.kt b/aztec/src/main/kotlin/org/wordpress/aztec/spans/MarkSpan.kt index 1b127c8cc..a75221286 100644 --- a/aztec/src/main/kotlin/org/wordpress/aztec/spans/MarkSpan.kt +++ b/aztec/src/main/kotlin/org/wordpress/aztec/spans/MarkSpan.kt @@ -34,6 +34,7 @@ class MarkSpan : CharacterStyle, IAztecInlineSpan { } fun getTextColor(): String { - return java.lang.String.format("#%06X", 0xFFFFFF and textColor!!) + val currentColor = textColor ?: 0 + return String.format("#%06X", 0xFFFFFF and currentColor) } } From 9639a10be430cf41193337fba8571365b8b08038 Mon Sep 17 00:00:00 2001 From: Gerardo Date: Mon, 22 Jan 2024 19:28:02 +0100 Subject: [PATCH 04/12] 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; } } } From 9b97880c701a493dbce23c401e2d2453a6e1e089 Mon Sep 17 00:00:00 2001 From: Gerardo Date: Mon, 22 Jan 2024 19:42:03 +0100 Subject: [PATCH 05/12] Fix lint issue --- .../kotlin/org/wordpress/aztec/formatting/InlineFormatter.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 b0705ab05..0b76079f2 100644 --- a/aztec/src/main/kotlin/org/wordpress/aztec/formatting/InlineFormatter.kt +++ b/aztec/src/main/kotlin/org/wordpress/aztec/formatting/InlineFormatter.kt @@ -272,7 +272,7 @@ class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle, private val h end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE ) - markStyleColor = null; + markStyleColor = null } } } From bdfb20f9d31ab35851c433e9e7ea620615b2b72d Mon Sep 17 00:00:00 2001 From: Gerardo Date: Tue, 27 Feb 2024 16:42:15 +0100 Subject: [PATCH 06/12] MarkSpan - Set color from HTML attributes if they exist --- .../src/main/kotlin/org/wordpress/aztec/spans/MarkSpan.kt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/aztec/src/main/kotlin/org/wordpress/aztec/spans/MarkSpan.kt b/aztec/src/main/kotlin/org/wordpress/aztec/spans/MarkSpan.kt index a75221286..7ba915490 100644 --- a/aztec/src/main/kotlin/org/wordpress/aztec/spans/MarkSpan.kt +++ b/aztec/src/main/kotlin/org/wordpress/aztec/spans/MarkSpan.kt @@ -4,6 +4,7 @@ import android.graphics.Color import android.text.TextPaint import android.text.style.CharacterStyle import org.wordpress.aztec.AztecAttributes +import org.wordpress.aztec.source.CssStyleFormatter class MarkSpan : CharacterStyle, IAztecInlineSpan { override var TAG = "mark" @@ -13,6 +14,12 @@ class MarkSpan : CharacterStyle, IAztecInlineSpan { constructor(attributes: AztecAttributes = AztecAttributes()) : super() { this.attributes = attributes + + val color = CssStyleFormatter.getStyleAttribute(attributes, + CssStyleFormatter.CSS_COLOR_ATTRIBUTE) + if (color.isNotEmpty()) { + textColor = Color.parseColor(color) + } } constructor(attributes: AztecAttributes = AztecAttributes(), colorString: String?) : super() { From ffdddf39d81f7792b7bf60dda717689ac5f249cb Mon Sep 17 00:00:00 2001 From: Gerardo Date: Thu, 29 Feb 2024 13:24:59 +0100 Subject: [PATCH 07/12] InlineFormatter - Prevent picking previous Mark styles if the format is no longer active --- .../org/wordpress/aztec/formatting/InlineFormatter.kt | 8 ++++++++ 1 file changed, 8 insertions(+) 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 0b76079f2..9b3d352d5 100644 --- a/aztec/src/main/kotlin/org/wordpress/aztec/formatting/InlineFormatter.kt +++ b/aztec/src/main/kotlin/org/wordpress/aztec/formatting/InlineFormatter.kt @@ -133,6 +133,14 @@ class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle, private val h return } + // Remove leading Mark formatting styles if the format is not active + if (!editor.selectedStyles.contains(AztecTextFormat.FORMAT_MARK) && newStart >=1 && end > 1) { + val markSpan = editableText.getSpans(newStart - 1, newStart, MarkSpan::class.java); + if (markSpan.isNotEmpty()) { + removeInlineCssStyle(newStart, end) + } + } + editableText.getSpans(newStart, end, IAztecInlineSpan::class.java).forEach { if (!editor.selectedStyles.contains(spanToTextFormat(it)) || ignoreSelectedStyles || (newStart == 0 && end == 0) || (newStart > end && editableText.length > end && editableText[end] == '\n')) { From bdc719ceb0263a6faa18b724de59f00e5c3e3236 Mon Sep 17 00:00:00 2001 From: Gerardo Date: Tue, 5 Mar 2024 21:22:30 +0100 Subject: [PATCH 08/12] Improve setting and resetting Mark formatting styles --- .../aztec/formatting/InlineFormatter.kt | 53 +++++++++++-------- 1 file changed, 31 insertions(+), 22 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 9b3d352d5..5baacb57e 100644 --- a/aztec/src/main/kotlin/org/wordpress/aztec/formatting/InlineFormatter.kt +++ b/aztec/src/main/kotlin/org/wordpress/aztec/formatting/InlineFormatter.kt @@ -125,6 +125,16 @@ class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle, private val h val newStart = if (start > end) end else start // if there is END_OF_BUFFER_MARKER at the end of or range, extend the range to include it + // Clear Mark formatting styles + if (!editor.selectedStyles.contains(AztecTextFormat.FORMAT_MARK) && start >= 1 && end > 1 ) { + val previousMarkSpan = editableText.getSpans(start - 1, start, MarkSpan::class.java); + val markSpan = editableText.getSpans(start, end, MarkSpan::class.java); + if (markSpan.isNotEmpty() || (previousMarkSpan.isNotEmpty() && markStyleColor == null)) { + removeInlineCssStyle(start, end) + return + } + } + // remove lingering empty spans when removing characters if (start > end) { editableText.getSpans(newStart, end, IAztecInlineSpan::class.java) @@ -133,14 +143,6 @@ class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle, private val h return } - // Remove leading Mark formatting styles if the format is not active - if (!editor.selectedStyles.contains(AztecTextFormat.FORMAT_MARK) && newStart >=1 && end > 1) { - val markSpan = editableText.getSpans(newStart - 1, newStart, MarkSpan::class.java); - if (markSpan.isNotEmpty()) { - removeInlineCssStyle(newStart, end) - } - } - editableText.getSpans(newStart, end, IAztecInlineSpan::class.java).forEach { if (!editor.selectedStyles.contains(spanToTextFormat(it)) || ignoreSelectedStyles || (newStart == 0 && end == 0) || (newStart > end && editableText.length > end && editableText[end] == '\n')) { @@ -266,21 +268,28 @@ class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle, private val h if (span != null) { val color = span.getTextColor() val currentSpanStart = editableText.getSpanStart(span) + val currentSpanEnd = editableText.getSpanEnd(span) - editableText.removeSpan(span) - editableText.setSpan( - MarkSpan(AztecAttributes(), color), - currentSpanStart, - start, - Spanned.SPAN_EXCLUSIVE_EXCLUSIVE - ) - editableText.setSpan( - MarkSpan(AztecAttributes(), markStyleColor), - start, - end, - Spanned.SPAN_EXCLUSIVE_EXCLUSIVE - ) - markStyleColor = null + if (end < currentSpanEnd) { + markStyleColor = null + return + } + + if (!color.equals(markStyleColor, ignoreCase = true)) { + editableText.removeSpan(span) + editableText.setSpan( + MarkSpan(AztecAttributes(), color), + currentSpanStart, + start, + Spanned.SPAN_EXCLUSIVE_EXCLUSIVE + ) + editableText.setSpan( + MarkSpan(AztecAttributes(), markStyleColor), + start, + end, + Spanned.SPAN_EXCLUSIVE_EXCLUSIVE + ) + } } } } From d83e764f5690a3e8f1266e3bb9ef97fda9e0771a Mon Sep 17 00:00:00 2001 From: Gerardo Date: Tue, 5 Mar 2024 21:26:44 +0100 Subject: [PATCH 09/12] Remove unnecessary semicolon --- .../kotlin/org/wordpress/aztec/formatting/InlineFormatter.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 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 5baacb57e..477ca8880 100644 --- a/aztec/src/main/kotlin/org/wordpress/aztec/formatting/InlineFormatter.kt +++ b/aztec/src/main/kotlin/org/wordpress/aztec/formatting/InlineFormatter.kt @@ -127,8 +127,8 @@ class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle, private val h // Clear Mark formatting styles if (!editor.selectedStyles.contains(AztecTextFormat.FORMAT_MARK) && start >= 1 && end > 1 ) { - val previousMarkSpan = editableText.getSpans(start - 1, start, MarkSpan::class.java); - val markSpan = editableText.getSpans(start, end, MarkSpan::class.java); + val previousMarkSpan = editableText.getSpans(start - 1, start, MarkSpan::class.java) + val markSpan = editableText.getSpans(start, end, MarkSpan::class.java) if (markSpan.isNotEmpty() || (previousMarkSpan.isNotEmpty() && markStyleColor == null)) { removeInlineCssStyle(start, end) return From 99b5c9f1042a0c12115d7ecbe0c2b21adaf50829 Mon Sep 17 00:00:00 2001 From: Gerardo Date: Thu, 7 Mar 2024 16:10:51 +0100 Subject: [PATCH 10/12] Remove markStyleColor check --- .../kotlin/org/wordpress/aztec/formatting/InlineFormatter.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 477ca8880..9134c81af 100644 --- a/aztec/src/main/kotlin/org/wordpress/aztec/formatting/InlineFormatter.kt +++ b/aztec/src/main/kotlin/org/wordpress/aztec/formatting/InlineFormatter.kt @@ -129,7 +129,7 @@ class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle, private val h if (!editor.selectedStyles.contains(AztecTextFormat.FORMAT_MARK) && start >= 1 && end > 1 ) { val previousMarkSpan = editableText.getSpans(start - 1, start, MarkSpan::class.java) val markSpan = editableText.getSpans(start, end, MarkSpan::class.java) - if (markSpan.isNotEmpty() || (previousMarkSpan.isNotEmpty() && markStyleColor == null)) { + if (markSpan.isNotEmpty() || previousMarkSpan.isNotEmpty()) { removeInlineCssStyle(start, end) return } From 17946f2be64e3177a4d1c52d98e53ac79985a1b2 Mon Sep 17 00:00:00 2001 From: Gerardo Date: Wed, 20 Mar 2024 19:15:04 +0100 Subject: [PATCH 11/12] InlineFormatter - Move markStyleColor declaration --- .../kotlin/org/wordpress/aztec/formatting/InlineFormatter.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 9134c81af..f72e99a13 100644 --- a/aztec/src/main/kotlin/org/wordpress/aztec/formatting/InlineFormatter.kt +++ b/aztec/src/main/kotlin/org/wordpress/aztec/formatting/InlineFormatter.kt @@ -37,10 +37,10 @@ import org.wordpress.aztec.watchers.TextChangedEvent class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle, private val highlightStyle: HighlightStyle) : AztecFormatter(editor) { var backgroundSpanColor: Int? = null + var markStyleColor: String? = null data class CodeStyle(val codeBackground: Int, val codeBackgroundAlpha: Float, val codeColor: Int) data class HighlightStyle(@ColorRes val color: Int) - var markStyleColor: String? = null fun toggle(textFormat: ITextFormat) { if (!containsInlineStyle(textFormat)) { From 2f735642025c364e5a6003505f40d1ee93159237 Mon Sep 17 00:00:00 2001 From: Gerardo Date: Thu, 21 Mar 2024 12:04:09 +0100 Subject: [PATCH 12/12] MarkSpan - Rename textColor variable to textColorValue, it also applies changes to how new values are set --- .../org/wordpress/aztec/spans/MarkSpan.kt | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/aztec/src/main/kotlin/org/wordpress/aztec/spans/MarkSpan.kt b/aztec/src/main/kotlin/org/wordpress/aztec/spans/MarkSpan.kt index 7ba915490..5c9b0f9a1 100644 --- a/aztec/src/main/kotlin/org/wordpress/aztec/spans/MarkSpan.kt +++ b/aztec/src/main/kotlin/org/wordpress/aztec/spans/MarkSpan.kt @@ -10,38 +10,36 @@ class MarkSpan : CharacterStyle, IAztecInlineSpan { override var TAG = "mark" override var attributes: AztecAttributes = AztecAttributes() - var textColor: Int? = null + private val textColorValue: Int? constructor(attributes: AztecAttributes = AztecAttributes()) : super() { this.attributes = attributes val color = CssStyleFormatter.getStyleAttribute(attributes, CssStyleFormatter.CSS_COLOR_ATTRIBUTE) - if (color.isNotEmpty()) { - textColor = Color.parseColor(color) + textColorValue = if (color.isNotEmpty()) { + Color.parseColor(color) + } else { + null } } constructor(attributes: AztecAttributes = AztecAttributes(), colorString: String?) : super() { this.attributes = attributes - if (colorString != null) { - textColor = Color.parseColor(colorString) + textColorValue = if (colorString != null) { + Color.parseColor(colorString) + } else { + null } } override fun updateDrawState(tp: TextPaint) { - configureTextPaint(tp) - } - - private fun configureTextPaint(tp: TextPaint) { - if (textColor != null) { - tp.color = textColor as Int - } + textColorValue?.let { tp.color = it } } fun getTextColor(): String { - val currentColor = textColor ?: 0 + val currentColor = textColorValue ?: 0 return String.format("#%06X", 0xFFFFFF and currentColor) } }