Skip to content

Commit 97a9023

Browse files
authored
Merge pull request #151 from halilozercan/halilozercan/fix-empty-items-list-layout
Fix #150
2 parents 812ed45 + 498f43c commit 97a9023

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

desktop-sample/src/main/kotlin/com/halilibo/richtext/desktop/MarkdownSampleApp.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import androidx.compose.foundation.layout.padding
1313
import androidx.compose.foundation.lazy.LazyColumn
1414
import androidx.compose.foundation.rememberScrollState
1515
import androidx.compose.foundation.text.BasicTextField
16+
import androidx.compose.foundation.text.input.rememberTextFieldState
1617
import androidx.compose.foundation.text.selection.DisableSelection
1718
import androidx.compose.foundation.text.selection.SelectionContainer
1819
import androidx.compose.foundation.verticalScroll
@@ -70,7 +71,7 @@ fun main(): Unit = singleWindowApplication(
7071
)
7172
) {
7273
SelectionContainer {
73-
var text by remember { mutableStateOf(sampleMarkdown) }
74+
val state = rememberTextFieldState(sampleMarkdown)
7475
Row(
7576
modifier = Modifier
7677
.padding(32.dp)
@@ -80,9 +81,7 @@ fun main(): Unit = singleWindowApplication(
8081
Column(modifier = Modifier.weight(1f)) {
8182
RichTextStyleConfig(richTextStyle = richTextStyle, onChanged = { richTextStyle = it })
8283
BasicTextField(
83-
value = text,
84-
onValueChange = { text = it },
85-
maxLines = Int.MAX_VALUE,
84+
state = state,
8685
modifier = Modifier
8786
.fillMaxHeight()
8887
.background(Color.LightGray)
@@ -111,7 +110,7 @@ fun main(): Unit = singleWindowApplication(
111110
modifier = Modifier.verticalScroll(rememberScrollState()),
112111
style = richTextStyle,
113112
) {
114-
Markdown(content = text)
113+
Markdown(content = state.text.toString())
115114
}
116115
} else {
117116
val parser = remember { CommonmarkAstNodeParser() }

richtext-ui/src/commonMain/kotlin/com/halilibo/richtext/ui/FormattedList.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,12 @@ private val LocalListLevel = compositionLocalOf { 0 }
275275
val widestItem = itemPlaceables.maxByOrNull { it.width }!!
276276

277277
val listWidth = widestPrefix.width + widestItem.width
278-
val listHeight = itemPlaceables.sumOf { it.height } +
278+
val itemsHeight = itemPlaceables.sumOf { it.height } +
279279
(itemPlaceables.size - 1) * itemSpacing.roundToPx()
280+
val prefixesHeight = prefixPlaceables.sumOf { it.height } +
281+
(prefixPlaceables.size - 1) * itemSpacing.roundToPx()
282+
283+
val listHeight = maxOf(itemsHeight, prefixesHeight)
280284
layout(listWidth, listHeight) {
281285
var y = 0
282286

0 commit comments

Comments
 (0)