Skip to content

Commit

Permalink
Update updating existing MarkSpan logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerardo committed Jan 22, 2024
1 parent c48c233 commit 9639a10
Showing 1 changed file with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}
}
Expand Down

0 comments on commit 9639a10

Please sign in to comment.