diff --git a/changelog.d/1090.bugfix b/changelog.d/1090.bugfix new file mode 100644 index 0000000000..7c93ed6879 --- /dev/null +++ b/changelog.d/1090.bugfix @@ -0,0 +1 @@ +Fix rendering of inline elements in list items. diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/html/DocumentProvider.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/html/DocumentProvider.kt index 249334cace..768b0e3ec3 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/html/DocumentProvider.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/html/DocumentProvider.kt @@ -50,5 +50,7 @@ open class DocumentProvider : PreviewParameterProvider { // "
pre
", "
In reply to " + "@alice:matrix.org
original message
reply", + "
  1. Testing link item.
  2. And another item.
", + "", ).map { Jsoup.parse(it) } } diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/html/HtmlDocument.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/html/HtmlDocument.kt index 5d07db73a5..bb3e7b7f10 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/html/HtmlDocument.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/html/HtmlDocument.kt @@ -400,22 +400,14 @@ private fun HtmlOrderedList( onTextClicked: () -> Unit = {}, onTextLongClicked: () -> Unit = {}, ) { - var number = 1 val delimiter = "." HtmlListItems( list = orderedList, + marker = { index -> "$index$delimiter"}, modifier = modifier, onTextClicked = onTextClicked, onTextLongClicked = onTextLongClicked, interactionSource = interactionSource - ) { - val text = buildAnnotatedString { - append("${number++}$delimiter ${it.text()}") - } - HtmlText( - text = text, onClick = onTextClicked, - onLongClick = onTextLongClicked, interactionSource = interactionSource - ) - } + ) } @Composable @@ -429,42 +421,52 @@ private fun HtmlUnorderedList( val marker = "・" HtmlListItems( list = unorderedList, + marker = { marker }, modifier = modifier, onTextClicked = onTextClicked, onTextLongClicked = onTextLongClicked, interactionSource = interactionSource - ) { - val text = buildAnnotatedString { - append("$marker ${it.text()}") - } - HtmlText( - text = text, onClick = onTextClicked, - onLongClick = onTextLongClicked, interactionSource = interactionSource - ) - } + ) } @Composable private fun HtmlListItems( list: Element, + marker: (Int) -> String, interactionSource: MutableInteractionSource, modifier: Modifier = Modifier, onTextClicked: () -> Unit = {}, onTextLongClicked: () -> Unit = {}, - content: @Composable (node: TextNode) -> Unit = {} ) { Column(modifier = modifier) { - for (node in list.children()) { - for (innerNode in node.childNodes()) { - when (innerNode) { - is TextNode -> { - if (!innerNode.isBlank) content(innerNode) + for ((index, node) in list.children().withIndex()) { + val areAllChildrenInline = node.childNodes().all { it is TextNode || it is Element && it.isInline() } + if (areAllChildrenInline) { + val text = buildAnnotatedString { + append("${marker(index + 1)} ") + appendInlineChildrenElements(node.childNodes(), MaterialTheme.colorScheme) + } + HtmlText(text = text, interactionSource = remember { MutableInteractionSource() }) + } else { + for (innerNode in node.childNodes()) { + when (innerNode) { + is TextNode -> { + if (!innerNode.isBlank) { + val text = buildAnnotatedString { + append("${marker(index + 1)} ") + } + HtmlText( + text = text, onClick = onTextClicked, + onLongClick = onTextLongClicked, interactionSource = interactionSource + ) + } + } + is Element -> HtmlBlock( + element = innerNode, + modifier = Modifier.padding(start = 4.dp), + onTextClicked = onTextClicked, onTextLongClicked = onTextLongClicked, + interactionSource = interactionSource + ) } - is Element -> HtmlBlock( - element = innerNode, - modifier = Modifier.padding(start = 4.dp), - onTextClicked = onTextClicked, onTextLongClicked = onTextLongClicked, - interactionSource = interactionSource - ) } } } diff --git a/tests/uitests/src/test/snapshots/images/ui_S_t[f.messages.impl.timeline.components.html_null_HtmlDocumentDark_0_null_16,NEXUS_5,1.0,en].png b/tests/uitests/src/test/snapshots/images/ui_S_t[f.messages.impl.timeline.components.html_null_HtmlDocumentDark_0_null_16,NEXUS_5,1.0,en].png index 665c8811ac..4fe37049d6 100644 --- a/tests/uitests/src/test/snapshots/images/ui_S_t[f.messages.impl.timeline.components.html_null_HtmlDocumentDark_0_null_16,NEXUS_5,1.0,en].png +++ b/tests/uitests/src/test/snapshots/images/ui_S_t[f.messages.impl.timeline.components.html_null_HtmlDocumentDark_0_null_16,NEXUS_5,1.0,en].png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:bb0d3bfcfd75cbd75fd9270ff1dc27090e5dbac79ca8db8a46d91a4c12bc966b -size 4457 +oid sha256:41d154cec3a16351c3c071ec8a198d36ed3d7745f8500f641fd765ad22f693df +size 10877 diff --git a/tests/uitests/src/test/snapshots/images/ui_S_t[f.messages.impl.timeline.components.html_null_HtmlDocumentDark_0_null_20,NEXUS_5,1.0,en].png b/tests/uitests/src/test/snapshots/images/ui_S_t[f.messages.impl.timeline.components.html_null_HtmlDocumentDark_0_null_20,NEXUS_5,1.0,en].png new file mode 100644 index 0000000000..de9c64a652 --- /dev/null +++ b/tests/uitests/src/test/snapshots/images/ui_S_t[f.messages.impl.timeline.components.html_null_HtmlDocumentDark_0_null_20,NEXUS_5,1.0,en].png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ce52e4fba5279920db75565f4cdcf1ca761a8aad7b09ad9428e490c396527294 +size 11600 diff --git a/tests/uitests/src/test/snapshots/images/ui_S_t[f.messages.impl.timeline.components.html_null_HtmlDocumentDark_0_null_21,NEXUS_5,1.0,en].png b/tests/uitests/src/test/snapshots/images/ui_S_t[f.messages.impl.timeline.components.html_null_HtmlDocumentDark_0_null_21,NEXUS_5,1.0,en].png new file mode 100644 index 0000000000..5a8ee5ffe0 --- /dev/null +++ b/tests/uitests/src/test/snapshots/images/ui_S_t[f.messages.impl.timeline.components.html_null_HtmlDocumentDark_0_null_21,NEXUS_5,1.0,en].png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8c24f6dd8748dc3d262f5590a281ac1caee261046943ade6170ac7fcadb6d4fa +size 11516 diff --git a/tests/uitests/src/test/snapshots/images/ui_S_t[f.messages.impl.timeline.components.html_null_HtmlDocumentLight_0_null_16,NEXUS_5,1.0,en].png b/tests/uitests/src/test/snapshots/images/ui_S_t[f.messages.impl.timeline.components.html_null_HtmlDocumentLight_0_null_16,NEXUS_5,1.0,en].png index 665c8811ac..cf3f824fd9 100644 --- a/tests/uitests/src/test/snapshots/images/ui_S_t[f.messages.impl.timeline.components.html_null_HtmlDocumentLight_0_null_16,NEXUS_5,1.0,en].png +++ b/tests/uitests/src/test/snapshots/images/ui_S_t[f.messages.impl.timeline.components.html_null_HtmlDocumentLight_0_null_16,NEXUS_5,1.0,en].png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:bb0d3bfcfd75cbd75fd9270ff1dc27090e5dbac79ca8db8a46d91a4c12bc966b -size 4457 +oid sha256:7240b9666592f3627bb2e944cc83ab31eface8139c5c98dcc6c1ad9e7ca9b8b6 +size 11285 diff --git a/tests/uitests/src/test/snapshots/images/ui_S_t[f.messages.impl.timeline.components.html_null_HtmlDocumentLight_0_null_20,NEXUS_5,1.0,en].png b/tests/uitests/src/test/snapshots/images/ui_S_t[f.messages.impl.timeline.components.html_null_HtmlDocumentLight_0_null_20,NEXUS_5,1.0,en].png new file mode 100644 index 0000000000..3312595f8a --- /dev/null +++ b/tests/uitests/src/test/snapshots/images/ui_S_t[f.messages.impl.timeline.components.html_null_HtmlDocumentLight_0_null_20,NEXUS_5,1.0,en].png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4c0a959f003d8eedf2a4b9284f63ea77a608e272d0dd8e564bbbbf3686c88758 +size 11572 diff --git a/tests/uitests/src/test/snapshots/images/ui_S_t[f.messages.impl.timeline.components.html_null_HtmlDocumentLight_0_null_21,NEXUS_5,1.0,en].png b/tests/uitests/src/test/snapshots/images/ui_S_t[f.messages.impl.timeline.components.html_null_HtmlDocumentLight_0_null_21,NEXUS_5,1.0,en].png new file mode 100644 index 0000000000..5a50bf3ace --- /dev/null +++ b/tests/uitests/src/test/snapshots/images/ui_S_t[f.messages.impl.timeline.components.html_null_HtmlDocumentLight_0_null_21,NEXUS_5,1.0,en].png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d3a3ffdc5062cea8c3226df50b0876a3ca02045a19e05974b95e5ac83b813f39 +size 11502