Skip to content

Commit

Permalink
Merge pull request #368 from MohamedRejeb/1.x
Browse files Browse the repository at this point in the history
Improve unordered list multiline items rendering
  • Loading branch information
MohamedRejeb authored Sep 29, 2024
2 parents 11a36b9 + 3477235 commit 5a5f552
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,6 @@ public class RichTextState internal constructor(
number = orderedListNumber,
initialIndent = config.listIndent,
startTextSpanStyle = firstRichSpan?.spanStyle ?: SpanStyle(),
startTextWidth = 0.sp
)
updateTextFieldValue(
newTextFieldValue = updateParagraphType(
Expand Down Expand Up @@ -2594,7 +2593,7 @@ public class RichTextState internal constructor(
textLayoutResult?.let { textLayoutResult ->
richParagraphList.forEachIndexed { index, richParagraph ->
val paragraphType = richParagraph.type
if (index + 1 > maxLines || paragraphType !is OrderedList)
if (index + 1 > maxLines || paragraphType !is ConfigurableStartTextWidth)
return@forEachIndexed

if (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.mohamedrejeb.richeditor.paragraph.type

import androidx.compose.ui.unit.TextUnit

internal interface ConfigurableStartTextWidth {

var startTextWidth: TextUnit

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal class OrderedList(
initialIndent: Int = DefaultListIndent,
startTextSpanStyle: SpanStyle = SpanStyle(),
startTextWidth: TextUnit = 0.sp
) : ParagraphType {
) : ParagraphType, ConfigurableStartTextWidth {

var number = number
set(value) {
Expand All @@ -31,7 +31,7 @@ internal class OrderedList(
style = getNewParagraphStyle()
}

var startTextWidth: TextUnit = startTextWidth
override var startTextWidth: TextUnit = startTextWidth
set(value) {
field = value
style = getNewParagraphStyle()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.mohamedrejeb.richeditor.paragraph.type

import androidx.compose.runtime.snapshotFlow
import androidx.compose.ui.text.ParagraphStyle
import androidx.compose.ui.text.style.TextIndent
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.sp
import com.mohamedrejeb.richeditor.annotation.ExperimentalRichTextApi
import com.mohamedrejeb.richeditor.model.DefaultListIndent
Expand All @@ -12,7 +12,14 @@ import com.mohamedrejeb.richeditor.paragraph.RichParagraph

internal class UnorderedList(
initialIndent: Int = DefaultListIndent,
): ParagraphType {
startTextWidth: TextUnit = 0.sp,
): ParagraphType, ConfigurableStartTextWidth {

override var startTextWidth: TextUnit = startTextWidth
set(value) {
field = value
style = getParagraphStyle()
}

private var indent = initialIndent

Expand All @@ -32,7 +39,7 @@ internal class UnorderedList(
ParagraphStyle(
textIndent = TextIndent(
firstLine = indent.sp,
restLine = indent.sp
restLine = (indent + startTextWidth.value).sp
)
)

Expand All @@ -45,12 +52,14 @@ internal class UnorderedList(

override fun getNextParagraphType(): ParagraphType =
UnorderedList(
initialIndent = indent
initialIndent = indent,
startTextWidth = startTextWidth
)

override fun copy(): ParagraphType =
UnorderedList(
initialIndent = indent
initialIndent = indent,
startTextWidth = startTextWidth
)

override fun equals(other: Any?): Boolean {
Expand Down

0 comments on commit 5a5f552

Please sign in to comment.