Skip to content

Commit 829b25b

Browse files
committed
Cleanup.
1 parent e5dbbdd commit 829b25b

File tree

2 files changed

+9
-45
lines changed

2 files changed

+9
-45
lines changed

aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ class AztecText : AppCompatAutoCompleteTextView, TextWatcher, UnknownHtmlSpan.On
9393

9494
private var isViewInitialized = false
9595
private var isLeadingStyleRemoved = false
96-
// private var isBackspacePressed = false
9796
private var previousCursorPosition = 0
9897

9998
var isInCalypsoMode = true
@@ -241,9 +240,6 @@ class AztecText : AppCompatAutoCompleteTextView, TextWatcher, UnknownHtmlSpan.On
241240
isLeadingStyleRemoved = true
242241
onSelectionChanged(0, 0)
243242
}
244-
// else if (selectionStart == selectionEnd) {
245-
// isBackspacePressed = true
246-
// }
247243
consumeKeyEvent = blockFormatter.tryRemoveBlockStyleFromFirstLine()
248244
}
249245

@@ -510,13 +506,9 @@ class AztecText : AppCompatAutoCompleteTextView, TextWatcher, UnknownHtmlSpan.On
510506

511507
previousCursorPosition = selEnd
512508

513-
// val isFirstCharacterDeleted = selStart == 0 && isBackspacePressed
514-
val isFirstCharacterDeleted = false
515509

516510
//do not update toolbar or selected styles when we removed the last character in editor
517-
//or when we removed first character in not empty editor
518-
if ((!isLeadingStyleRemoved && length() == 1 && text[0] == Constants.END_OF_BUFFER_MARKER)) {
519-
// isBackspacePressed = false
511+
if (!isLeadingStyleRemoved && length() == 1 && text[0] == Constants.END_OF_BUFFER_MARKER) {
520512
return
521513
}
522514

@@ -1109,9 +1101,6 @@ class AztecText : AppCompatAutoCompleteTextView, TextWatcher, UnknownHtmlSpan.On
11091101
onSelectionChanged(0, 0)
11101102
return false
11111103
}
1112-
// else if (selectionStart == selectionEnd) {
1113-
// isBackspacePressed = true
1114-
// }
11151104

11161105
if (isStyleRemoved) {
11171106
history.handleHistory(this@AztecText)

aztec/src/main/kotlin/org/wordpress/aztec/formatting/InlineFormatter.kt

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)