Fix multi-line split inline code background drawing (#7875)

In the new timeline renderer, the line end position is sometimes incorrectly returned when you pass the offset of the last character in the line, returning `0.0f`.

This caused the shape to draw for the line to be reversed, where the start was `0.0f` and the end was the actual start.

When we detect a `0.0f` returned value for this,  just get the coordinates for the end of the line instead.
This commit is contained in:
Jorge Martin Espinosa
2026-10-07 15:10:19 +02:00
committed by GitHub
parent 3fe0e09e3c
commit a9d7e7e5ab
@@ -70,6 +70,7 @@ import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.rememberTextMeasurer
import androidx.compose.ui.text.style.ResolvedTextDirection
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.Dp
@@ -513,7 +514,7 @@ private fun Modifier.drawInlineCodeBackgrounds(
val lineEnd = minOf(range.end, layout.getLineEnd(line, visibleEnd = true))
if (lineEnd <= lineStart) continue
val startX = layout.getHorizontalPosition(lineStart, usePrimaryDirection = true)
val endX = layout.getHorizontalPosition(lineEnd, usePrimaryDirection = true)
val endX = layout.getHorizontalPosition(lineEnd, usePrimaryDirection = true).takeUnless { it == 0f } ?: layout.getLineEndPosition(line)
val left = minOf(startX, endX) - horizontalPadding
val right = maxOf(startX, endX) + horizontalPadding
val topLeft = Offset(left, layout.getLineTop(line))
@@ -540,6 +541,16 @@ private fun Modifier.drawInlineCodeBackgrounds(
}
}
private fun TextLayoutResult.getLineEndPosition(line: Int): Float {
val lineEnd = getLineEnd(line, visibleEnd = true)
val direction = getParagraphDirection(lineEnd)
return if (direction == ResolvedTextDirection.Ltr) {
getLineRight(line)
} else {
getLineLeft(line)
}
}
/**
* Detects taps and long presses on link-annotated ranges ([LINK_ANNOTATION_TAG]) without consuming the touch events if none are detected, and invokes the
* appropriate callbacks in [context].