Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import com.swmansion.enriched.markdown.utils.common.parseLinkPillContent
import com.swmansion.enriched.markdown.utils.common.parseLinkRecognition
import com.swmansion.enriched.markdown.utils.text.extensions.replaceMathSpansWithPlaceholders
import com.swmansion.enriched.markdown.utils.text.span.prepareWidthAwareSpans
import com.swmansion.enriched.markdown.utils.text.view.inViewSpanOrder
import java.util.concurrent.ConcurrentHashMap
import kotlin.math.ceil

Expand Down Expand Up @@ -755,7 +756,7 @@ object MeasurementStore {
): StaticLayout {
val builder =
StaticLayout.Builder
.obtain(content, 0, content.length, paint, widthPx)
.obtain(inViewSpanOrder(content), 0, content.length, paint, widthPx)
.setIncludePad(false)
.setLineSpacing(0f, 1f)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.swmansion.enriched.markdown.styles.StyleConfig
import com.swmansion.enriched.markdown.utils.common.BoundsForWidthUtils
import com.swmansion.enriched.markdown.utils.text.extensions.replaceMathSpansWithPlaceholders
import com.swmansion.enriched.markdown.utils.text.span.prepareWidthAwareSpans
import com.swmansion.enriched.markdown.utils.text.view.inViewSpanOrder
import kotlin.math.ceil

/** A stack's height and, for the root stack, the widest text line (px). */
Expand Down Expand Up @@ -219,7 +220,7 @@ object SegmentHeightMeasurer {
}
prepareWidthAwareSpans(text, widthPx)
return StaticLayout.Builder
.obtain(text, 0, text.length, paint, widthPx)
.obtain(inViewSpanOrder(text), 0, text.length, paint, widthPx)
.setIncludePad(false)
.setLineSpacing(0f, 1f)
.apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ private object NoCopySpannableFactory : Spannable.Factory() {
}
}

/**
* [text] as the markdown text view lays it out. Build every StaticLayout that sizes such
* a view from this: span order decides which LineHeightSpan wins on a shared line, so a
* layout over the bare builder can measure lines shorter than the view draws them.
*/
internal fun inViewSpanOrder(text: CharSequence): CharSequence =
if (text is SpannableStringBuilder) InsertionOrderedSpannable(text) else text

/**
* Hides that [buffer] is a `SpannableStringBuilder`. Layout reads a builder's paragraph
* spans in position order rather than insertion order, which paints nested list margins
Expand Down
Loading