@@ -109,23 +109,22 @@ class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle) : AztecFormat
109109 }
110110
111111 private fun clearInlineStyles (start : Int , end : Int , ignoreSelectedStyles : Boolean ) {
112- val newStart = Math .min (start, end)
112+ val newStart = if (start > end) end else start
113113 // if there is END_OF_BUFFER_MARKER at the end of or range, extend the range to include it
114- var newEnd = end
115114
116115 // remove lingering empty spans when removing characters
117116 if (start > end) {
118- editableText.getSpans(newStart, newEnd , AztecInlineSpan ::class .java)
117+ editableText.getSpans(newStart, end , AztecInlineSpan ::class .java)
119118 .filter { editableText.getSpanStart(it) == editableText.getSpanEnd(it) }
120119 .forEach { editableText.removeSpan(it) }
121120 return
122121 }
123122
124123
125- editableText.getSpans(newStart, newEnd , AztecInlineSpan ::class .java).forEach {
126- if (! editor.selectedStyles.contains(spanToTextFormat(it)) || ignoreSelectedStyles || (newStart == 0 && newEnd == 0 ) ||
127- (newStart > newEnd && editableText.length > newEnd && editableText[newEnd ] == ' \n ' )) {
128- removeInlineStyle(it, newStart, newEnd )
124+ editableText.getSpans(newStart, end , AztecInlineSpan ::class .java).forEach {
125+ if (! editor.selectedStyles.contains(spanToTextFormat(it)) || ignoreSelectedStyles || (newStart == 0 && end == 0 ) ||
126+ (newStart > end && editableText.length > end && editableText[end ] == ' \n ' )) {
127+ removeInlineStyle(it, newStart, end )
129128 }
130129
131130 }
@@ -239,31 +238,7 @@ class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle) : AztecFormat
239238 }
240239
241240 fun removeInlineStyle (textFormat : TextFormat , start : Int = selectionStart, end : Int = selectionEnd) {
242- // for convenience sake we are initializing the span of same type we are planing to remove
243- val spanToRemove = makeInlineSpan(textFormat)
244-
245- val spans = editableText.getSpans(start, end, AztecInlineSpan ::class .java)
246- val list = ArrayList <AztecPart >()
247-
248- spans.forEach {
249- if (isSameInlineSpanType(it, spanToRemove)) {
250- list.add(AztecPart (editableText.getSpanStart(it), editableText.getSpanEnd(it)))
251- editableText.removeSpan(it)
252- }
253- }
254-
255- list.forEach {
256- if (it.isValid) {
257- if (it.start < start) {
258- applyInlineStyle(textFormat, it.start, start)
259- }
260- if (it.end > end) {
261- applyInlineStyle(textFormat, end, it.end)
262- }
263- }
264- }
265-
266- joinStyleSpans(start, end)
241+ removeInlineStyle(makeInlineSpan(textFormat), start, end)
267242 }
268243
269244 fun isSameInlineSpanType (firstSpan : AztecInlineSpan , secondSpan : AztecInlineSpan ): Boolean {
@@ -422,7 +397,7 @@ class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle) : AztecFormat
422397 val selectionStart = editor.selectionStart
423398 val selectionEnd = editor.selectionEnd
424399
425- if (( selectionStart == 1 && selectionEnd == selectionStart) ) {
400+ if (selectionStart == 1 && selectionEnd == selectionStart) {
426401 editableText.getSpans(0 , 0 , AztecInlineSpan ::class .java).forEach {
427402 if (editableText.getSpanEnd(it) == selectionEnd && editableText.getSpanEnd(it) == selectionStart) {
428403 editableText.removeSpan(it)
0 commit comments