@devries-cameron20 / t3code-1 / commits / 0b7caf2a19
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(mobile): Android diff ellipsis no longer measures text quadratically (#26174)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 27, 2026 at 16:25 UTC 0b7caf2a199dc3915e7432807672657be61afd69
1 file changed +15 -4
apps/mobile/modules/t3-review-diff/android/src/main/java/expo/modules/t3reviewdiff/T3ReviewDiffView.kt
+15 -4
@@ -1423,13 +1423,24 @@ private fun centeredBaseline(top: Int, bottom: Int, paint: Paint): Float {
1423 return (top + bottom) / 2f - (metrics.ascent + metrics.descent) / 2f
1424 }
1425
1426 +// A single-line preview never shows this many characters, so longer text is cut before measuring.
1427 +private const val ELLIPSIZE_MAX_CHARS = 500
1428 +
1429 private fun ellipsize(value: String, paint: Paint, width: Float): String {
1427 - if (paint.measureText(value) <= width) return value
1430 + val truncated = value.length > ELLIPSIZE_MAX_CHARS
1431 + val capEnd = surrogateSafeEnd(value, ELLIPSIZE_MAX_CHARS)
1432 + val text = if (truncated) value.substring(0, capEnd) else value
1433 + if (!truncated && paint.measureText(text) <= width) return value
1434 val suffix = "..."
1435 val available = max(0f, width - paint.measureText(suffix))
1430 - var end = value.length
1431 - while (end > 0 && paint.measureText(value, 0, end) > available) end -= 1
1432 - return value.substring(0, end) + suffix
1436 + val end = surrogateSafeEnd(text, paint.breakText(text, true, available, null))
1437 + return text.substring(0, end) + suffix
1438 +}
1439 +
1440 +private fun surrogateSafeEnd(value: String, end: Int): Int {
1441 + val splitsPair = end in 1 until value.length &&
1442 + Character.isSurrogatePair(value[end - 1], value[end])
1443 + return if (splitsPair) end - 1 else end
1444 }
1445
1446 private fun indexFileHeaders(rows: List<DiffRow>): IntArray {