Skip to content

Commit 015f076

Browse files
committed
Fixed so list items are not immediately given newlines if followed by paragraph
1 parent f1a3a23 commit 015f076

File tree

5 files changed

+22
-5
lines changed

5 files changed

+22
-5
lines changed

app/src/main/java/com/nononsenseapps/feeder/ui/compose/text/AnnotatedString.kt

+14
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,20 @@ class AnnotatedParagraphStringBuilder {
3535
return false
3636
}
3737

38+
val endsWithNonBreakingSpace: Boolean
39+
get() {
40+
if (mLastTwoChars.isEmpty()) {
41+
return false
42+
}
43+
mLastTwoChars.peekLatest()?.let { latest ->
44+
if (latest.code == 160) {
45+
return true
46+
}
47+
}
48+
49+
return false
50+
}
51+
3852
fun pushVerbatimTtsAnnotation(verbatim: String) =
3953
builder.pushTtsAnnotation(VerbatimTtsAnnotation(verbatim))
4054

app/src/main/java/com/nononsenseapps/feeder/ui/compose/text/AnnotatedStringComposer.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ class AnnotatedStringComposer : HtmlParser() {
99
strings
1010

1111
override fun emitParagraph(): Boolean {
12-
if (builder.isEmpty()) {
12+
// List items emit dots and non-breaking space. Don't newline after that
13+
if (builder.isEmpty() || builder.endsWithNonBreakingSpace) {
1314
// Nothing to emit, and nothing to reset
1415
return false
1516
}

app/src/main/java/com/nononsenseapps/feeder/ui/compose/text/EagerComposer.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ class EagerComposer(
4343
}
4444

4545
override fun emitParagraph(): Boolean {
46-
if (builder.isEmpty()) {
46+
// List items emit dots and non-breaking space. Don't newline after that
47+
if (builder.isEmpty() || builder.endsWithNonBreakingSpace) {
4748
// Nothing to emit, and nothing to reset
4849
return false
4950
}

app/src/main/java/com/nononsenseapps/feeder/ui/compose/text/HtmlToComposable.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ private fun HtmlComposer.appendTextChildren(
578578
.forEach { listItem ->
579579
withParagraph {
580580
// no break space
581-
append(" ")
581+
append("\u00A0")
582582
appendTextChildren(
583583
listItem.childNodes(),
584584
baseUrl = baseUrl,
@@ -595,7 +595,7 @@ private fun HtmlComposer.appendTextChildren(
595595
.forEachIndexed { i, listItem ->
596596
withParagraph {
597597
// no break space
598-
append("${i + 1}. ")
598+
append("${i + 1}.\u00A0")
599599
appendTextChildren(
600600
listItem.childNodes(),
601601
baseUrl = baseUrl,

app/src/main/java/com/nononsenseapps/feeder/ui/compose/text/LazyListComposer.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ class LazyListComposer(
1111
) : HtmlComposer() {
1212

1313
override fun emitParagraph(): Boolean {
14-
if (builder.isEmpty()) {
14+
// List items emit dots and non-breaking space. Don't newline after that
15+
if (builder.isEmpty() || builder.endsWithNonBreakingSpace) {
1516
// Nothing to emit, and nothing to reset
1617
return false
1718
}

0 commit comments

Comments
 (0)