Skip to content

Commit

Permalink
Improve setting and resetting Mark formatting styles
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerardo committed Mar 5, 2024
1 parent ffdddf3 commit bdc719c
Showing 1 changed file with 31 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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')) {
Expand Down Expand Up @@ -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
)
}
}
}
}
Expand Down

0 comments on commit bdc719c

Please sign in to comment.