Skip to content

Commit 2349640

Browse files
committed
Fixed problem with ident elements
1 parent daa0a61 commit 2349640

File tree

4 files changed

+25
-16
lines changed

4 files changed

+25
-16
lines changed

app/src/main/kotlin/org/wordpress/aztec/demo/MainActivity.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ open class MainActivity : AppCompatActivity(),
115115
" <li>Nine</li>\n" +
116116
" <li>Eight</li>\n" +
117117
"</ol>"
118+
private val ORDERED_REVERSED_WITH_START_IDENT = "<h4>Reversed Start in 4 List:</h4>" +
119+
"<ol reversed>" +
120+
"<li>dkfdskfdf\\sd\\</li><li>dfds</li><li>fdf</li><li>dfd</li><li>f</li><li>dsfs<ol><li>fdfd</li><li>f</li><li>dsf</li><li>ds</li><li>d</li><li>g</li><li>sdg</li><li>ds</li></ol></li></ol>\n"
118121
private val LINE = "<hr />"
119122
private val UNORDERED = "<ul><li style=\"color:darkred\">Unordered</li><li>Should not have color</li></ul>"
120123
private val QUOTE = "<blockquote>Quote</blockquote>"
@@ -175,6 +178,7 @@ open class MainActivity : AppCompatActivity(),
175178
ORDERED_REVERSED +
176179
ORDERED_REVERSED_WITH_START +
177180
ORDERED_REVERSED_NEGATIVE_WITH_START +
181+
ORDERED_REVERSED_WITH_START_IDENT +
178182
LINE +
179183
UNORDERED +
180184
QUOTE +

aztec/src/main/kotlin/org/wordpress/aztec/spans/AztecListSpan.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ abstract class AztecListSpan(override var nestingLevel: Int,
3434
}
3535
}
3636

37-
fun getIndexOfProcessedLine(text: CharSequence, end: Int): Int {
37+
fun getIndexOfProcessedLine(text: CharSequence, end: Int): Int? {
3838
val spanStart = (text as Spanned).getSpanStart(this)
3939
val spanEnd = text.getSpanEnd(this)
4040

@@ -44,7 +44,7 @@ abstract class AztecListSpan(override var nestingLevel: Int,
4444
val hasSublist = listText.getSpans(end - spanStart - 1, end - spanStart, AztecListSpan::class.java)
4545
.any { it.nestingLevel > nestingLevel }
4646
if (hasSublist) {
47-
return -1
47+
return null
4848
}
4949
}
5050

@@ -55,7 +55,7 @@ abstract class AztecListSpan(override var nestingLevel: Int,
5555
.any { it.nestingLevel == nestingLevel + 1 && listText.getSpanStart(it) == startOfLine }
5656

5757
if (!isValidListItem) {
58-
return -1
58+
return null
5959
}
6060

6161
// count the list item spans up to the current line with the expected nesting level => item number
@@ -71,7 +71,9 @@ abstract class AztecListSpan(override var nestingLevel: Int,
7171

7272
val listText = text.subSequence(spanStart, spanEnd) as Spanned
7373

74-
return listText.getSpans(0, listText.length, AztecListItemSpan::class.java).size
74+
return listText.getSpans(0, listText.length, AztecListItemSpan::class.java)
75+
.filter { it.nestingLevel == nestingLevel + 1 }
76+
.size
7577
}
7678

7779
fun nestingDepth(text: Spanned, index: Int, nextIndex: Int): Int {

aztec/src/main/kotlin/org/wordpress/aztec/spans/AztecOrderedListSpan.kt

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,21 @@ class AztecOrderedListSpan(
6161
0
6262
}
6363

64-
val isReversed = attributes.hasAttribute("reversed")
65-
val lineIndex = if (start > 0) {
66-
if (isReversed) start - (getIndexOfProcessedLine(text, end) - 1)
67-
else start + (getIndexOfProcessedLine(text, end) - 1)
68-
} else {
69-
val number = getNumberOfItemsInProcessedLine(text)
70-
if (isReversed) number - (getIndexOfProcessedLine(text, end) - 1)
71-
else getIndexOfProcessedLine(text, end)
72-
}
73-
74-
val textToDraw = if (dir >= 0) lineIndex.toString() + "."
64+
var textToDraw = ""
65+
getIndexOfProcessedLine(text, end)?.let {
66+
val isReversed = attributes.hasAttribute("reversed")
67+
val lineIndex = if (start > 0) {
68+
if (isReversed) start - (it - 1)
69+
else start + (it - 1)
70+
} else {
71+
val number = getNumberOfItemsInProcessedLine(text)
72+
if (isReversed) number - (it - 1)
73+
else it
74+
}
75+
76+
textToDraw = if (dir >= 0) lineIndex.toString() + "."
7577
else "." + lineIndex.toString()
78+
}
7679

7780
val width = p.measureText(textToDraw)
7881
maxWidth = Math.max(maxWidth, width)

aztec/src/main/kotlin/org/wordpress/aztec/spans/AztecUnorderedListSpan.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class AztecUnorderedListSpan(
5353
p.style = Paint.Style.FILL
5454

5555
val lineIndex = getIndexOfProcessedLine(text, end)
56-
val textToDraw = if (lineIndex > -1) "\u2022" else ""
56+
val textToDraw = if (lineIndex != null) "\u2022" else ""
5757

5858
val width = p.measureText(textToDraw)
5959

0 commit comments

Comments
 (0)