Compare commits

...
Author SHA1 Message Date
The412Banner 5c8a54ef95 fix(agent): keep replies with tables still while the theme color cycles
The Markdown renderer baked the link and code colors into its spans and
was rebuilt on every color step, so each step parsed the reply again and
reset its table rows, which measure one line high until drawn. Link and
code colors now come from the TextView and a live code theme, so a color
step only recolors the reply.
2026-11-29 15:52:51 +00:00
Kurt Himebauch 80fc5dec07 Fix the Steam home's wall and card fan on portrait screens (#3412) 2026-11-29 10:17:44 -05:00
8 changed files with 252 additions and 31 deletions

No files matched your search

@@ -2,6 +2,7 @@ package com.droiddeck.launcher.ui
import android.content.Context
import android.content.Intent
import android.graphics.Paint
import android.net.Uri
import android.text.Selection
import android.text.Spannable
@@ -22,8 +23,11 @@ import com.droiddeck.launcher.R
import io.noties.markwon.AbstractMarkwonPlugin
import io.noties.markwon.Markwon
import io.noties.markwon.MarkwonConfiguration
import io.noties.markwon.MarkwonSpansFactory
import io.noties.markwon.MarkwonVisitor
import io.noties.markwon.core.MarkwonTheme
import io.noties.markwon.core.spans.CodeBlockSpan
import io.noties.markwon.core.spans.CodeSpan
import io.noties.markwon.ext.strikethrough.StrikethroughPlugin
import io.noties.markwon.ext.tables.TableAwareMovementMethod
import io.noties.markwon.ext.tables.TablePlugin
@@ -35,7 +39,10 @@ import org.commonmark.ext.gfm.tables.TableCell
import org.commonmark.ext.gfm.tables.TableHead
import org.commonmark.ext.gfm.tables.TableRow
import org.commonmark.node.AbstractVisitor
import org.commonmark.node.Code
import org.commonmark.node.CustomNode
import org.commonmark.node.FencedCodeBlock
import org.commonmark.node.IndentedCodeBlock
import org.commonmark.node.Node
@Composable
@@ -46,9 +53,8 @@ internal fun AgentMarkdown(text: String, modifier: Modifier) {
val density = LocalDensity.current
val textSize = with(density) { 15.sp.toPx() }
val lineSpacing = with(density) { 3.sp.toPx() }
val renderer = remember(context, pal.primary2, pal.surfaceVariant, density) {
agentMarkdownRenderer(context, pal.primary2.toArgb(), pal.surfaceVariant.toArgb())
}
val theme = remember(context, pal.id, density) { AgentMarkdownTheme(context) }
val renderer = remember(theme) { agentMarkdownRenderer(context, theme) }
val rendered = remember(renderer, text) { renderer.toMarkdown(text) }
AndroidView(
modifier = modifier,
@@ -62,12 +68,25 @@ internal fun AgentMarkdown(text: String, modifier: Modifier) {
view.setLinkTextColor(pal.primary2.toArgb())
view.setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, textSize)
view.setLineSpacing(lineSpacing, 1f)
val codeBackground = pal.surfaceVariant.toArgb()
if (theme.codeBackground != codeBackground) {
theme.codeBackground = codeBackground
view.invalidate()
}
setAgentMarkdown(view, renderer, rendered)
},
)
}
internal fun agentMarkdownRenderer(context: Context, linkColor: Int, codeBackground: Int): Markwon =
internal class AgentMarkdownTheme(context: Context) : MarkwonTheme(MarkwonTheme.builderWithDefaults(context)) {
var codeBackground = 0
override fun getCodeBackgroundColor(paint: Paint) = codeBackground
override fun getCodeBlockBackgroundColor(paint: Paint) = codeBackground
}
internal fun agentMarkdownRenderer(context: Context, theme: AgentMarkdownTheme): Markwon =
Markwon.builder(context)
.usePlugin(StrikethroughPlugin.create())
.usePlugin(TablePlugin.create(context))
@@ -104,8 +123,10 @@ internal fun agentMarkdownRenderer(context: Context, linkColor: Int, codeBackgro
builder.append(text)
}
override fun configureTheme(builder: MarkwonTheme.Builder) {
builder.linkColor(linkColor).codeBackgroundColor(codeBackground)
override fun configureSpansFactory(builder: MarkwonSpansFactory.Builder) {
builder.setFactory(Code::class.java) { _, _ -> CodeSpan(theme) }
builder.setFactory(FencedCodeBlock::class.java) { _, _ -> CodeBlockSpan(theme) }
builder.setFactory(IndentedCodeBlock::class.java) { _, _ -> CodeBlockSpan(theme) }
}
override fun configureConfiguration(builder: MarkwonConfiguration.Builder) {
@@ -57,12 +57,17 @@ import com.droiddeck.launcher.stores.StoresState
/** What the Library pretends while a developer previews it. Nothing here is saved: a restart always comes back to [OFF]. */
internal enum class LibraryPreview { OFF, NOTHING_INSTALLED, SIGNED_OUT, SAMPLE }
/** How many games the Steam home pretends are installed. Nothing here is saved. */
internal enum class SteamHomePreview(val games: Int) { OFF(-1), NONE(0), FEW(3), MANY(12) }
internal enum class DrawerPreview { STEAM, DESKTOP, GAME }
/** Developer tools' preview states: screens that are otherwise hard to reach, shown without changing anything real. */
internal object DevPreview {
var library by mutableStateOf(LibraryPreview.OFF)
var drawer by mutableStateOf<DrawerPreview?>(null)
var steamHome by mutableStateOf(SteamHomePreview.OFF)
var openSteam by mutableStateOf(false)
/** The UI zoo sheet: where previews are picked, one at a time, only when asked for. */
var zoo by mutableStateOf(false)
/** Opt-in: a preview button where its state lives (the Library's toolbar), for switching states without the zoo. */
@@ -87,6 +92,41 @@ internal fun sampleOwned(store: Store): List<CatalogItem> =
internal fun sampleInstalled(owned: Map<Store, List<CatalogItem>>): Set<String> =
owned.values.flatMap { items -> items.take(SAMPLE_INSTALLED).map { it.key } }.toSet()
/** The Steam home's games while a developer previews it: this many invented titles, no art, nothing installed. */
internal fun sampleSteamHomeGames(count: Int): List<com.droiddeck.launcher.frontend.Library.SteamGame> = listOf(
"Portal 2", "Hades", "Celeste", "Stardew Valley", "Hollow Knight", "Balatro",
"Dead Cells", "Terraria", "Vampire Survivors", "Slay the Spire", "Cuphead", "Inscryption",
).take(count).mapIndexed { i, name ->
com.droiddeck.launcher.frontend.Library.SteamGame(1000 + i, name, art = null, library = "steam", lastPlayed = 1_700_000_000_000L - i * 86_400_000L)
}
/** The pill a previewed Steam home shows, so the fake state is never mistaken for the real one. */
@Composable
internal fun SteamHomePreviewPill(modifier: Modifier = Modifier) {
val preview = DevPreview.steamHome
if (preview == SteamHomePreview.OFF) return
val colors = MaterialTheme.colorScheme
val pal = LocalPalette.current
val label = stringResource(
when (preview) {
SteamHomePreview.NONE -> R.string.dev_preview_steam_none
SteamHomePreview.FEW -> R.string.dev_preview_steam_few
else -> R.string.dev_preview_steam_many
},
)
val end = stringResource(R.string.dev_preview_end)
Row(
verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp),
modifier = modifier.background(colors.surface, CircleShape).border(1.dp, pal.signal, CircleShape)
.clickable(role = Role.Button, onClickLabel = end) { DevPreview.steamHome = SteamHomePreview.OFF }
.padding(start = 14.dp, end = 10.dp, top = 8.dp, bottom = 8.dp).testTag("dev-preview-steam-end"),
) {
Icon(Icons.Outlined.Visibility, null, tint = pal.signal, modifier = Modifier.size(18.dp))
Text(stringResource(R.string.dev_preview_banner, label), fontSize = 13.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground)
Icon(Icons.Filled.Close, end, tint = colors.onSurfaceVariant, modifier = Modifier.size(18.dp))
}
}
/** The pill a previewed Library shows, so the fake state is never mistaken for the real one. */
@Composable
internal fun LibraryPreviewPill(modifier: Modifier = Modifier) {
@@ -215,6 +255,17 @@ internal fun UiZooSheet() {
DrawerPreview.GAME to R.string.session_title_game,
)) ActionRow(stringResource(label), null, show, onClick = { close(); DevPreview.drawer = mode }, modifier = Modifier.testTag("zoo-drawer-${mode.name.lowercase()}"))
}
SettingsGroup(stringResource(R.string.dev_preview_steam_home)) {
for ((mode, label) in listOf(
SteamHomePreview.NONE to R.string.dev_preview_steam_none,
SteamHomePreview.FEW to R.string.dev_preview_steam_few,
SteamHomePreview.MANY to R.string.dev_preview_steam_many,
)) ActionRow(
stringResource(label), null, show,
onClick = { close(); DevPreview.steamHome = mode; DevPreview.openSteam = true },
modifier = Modifier.testTag("zoo-steam-${mode.name.lowercase()}"),
)
}
SettingsGroup(stringResource(R.string.dev_preview_library)) {
for ((mode, label) in listOf(
LibraryPreview.NOTHING_INSTALLED to R.string.dev_preview_library_nothing_installed,
@@ -272,7 +272,10 @@ private fun Content(
return
}
if (selected == "steam") {
SteamHome(s, a, modifier)
Box(modifier) {
SteamHome(s, a, Modifier.fillMaxSize())
SteamHomePreviewPill(Modifier.align(androidx.compose.ui.Alignment.BottomCenter).padding(bottom = 20.dp))
}
return
}
if (selected == "store") {
@@ -658,6 +658,11 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com
LaunchedEffect(SetupTabs.openSection) {
if (SetupTabs.openSection != null && (railSelection != "setup" || s.pageKey != null)) showRailPage("setup", true)
}
LaunchedEffect(DevPreview.openSteam) {
if (!DevPreview.openSteam) return@LaunchedEffect
DevPreview.openSteam = false
showRailPage("steam", true)
}
LaunchedEffect(DevPreview.openLibrary) {
if (!DevPreview.openLibrary) return@LaunchedEffect
DevPreview.openLibrary = false
@@ -113,7 +113,8 @@ internal fun SteamHome(s: FrontEndState, a: FrontEndActions, modifier: Modifier)
}
val owned = remember(ownedAll, concealed) { ownedAll.filter { it.first.toLong() !in concealed } }
val featured = remember(featuredAll, concealed) { featuredAll.filter { it.appId.toLong() !in concealed } }
val games = remember(s.steamGames, LibraryHidden.keys, LibraryHidden.steam) { s.steamGames.filterNot { LibraryHidden.isHidden(hideKey(it), it) }.sortedWith(compareByDescending<Library.SteamGame> { it.lastPlayed }.thenBy { it.gameId }) }
val previewing = DevPreview.steamHome
val games = remember(s.steamGames, previewing, LibraryHidden.keys, LibraryHidden.steam) { (if (previewing == SteamHomePreview.OFF) s.steamGames else sampleSteamHomeGames(previewing.games)).filterNot { LibraryHidden.isHidden(hideKey(it), it) }.sortedWith(compareByDescending<Library.SteamGame> { it.lastPlayed }.thenBy { it.gameId }) }
val narrow = LocalNarrowPane.current
var words by remember { mutableStateOf<Rect?>(null) }
val mode = com.droiddeck.launcher.session.SessionService.MODE_STEAM
@@ -163,12 +164,12 @@ internal fun SteamHome(s: FrontEndState, a: FrontEndActions, modifier: Modifier)
games.isEmpty() -> EmptyLibrary(
avoid = words,
wall = if (owned.isEmpty() && featured.isEmpty()) null else { { CapsuleWall(emptyList(), owned = owned, featured = featured) } },
) { Box(Modifier.fillMaxSize().graphicsLayer { scaleX = 1.06f; scaleY = 1.06f }) { WallFade() } }
) { Box(Modifier.fillMaxSize().graphicsLayer { scaleX = 1.06f; scaleY = 1.06f }) { WallFade(bottomWhenTall = true) } }
games.size < WALL_MIN_GAMES -> CapsuleFan(games)
else -> CapsuleWall(games, owned = owned, featured = featured)
}
},
scrim = { if (games.size >= WALL_MIN_GAMES) WallFade() },
scrim = { if (games.size >= WALL_MIN_GAMES) WallFade(bottomWhenTall = true) },
words = {
val onboardingActive by com.droiddeck.launcher.session.Onboarding.active.collectAsState()
val onboardingFailed by com.droiddeck.launcher.session.Onboarding.failed.collectAsState()
@@ -232,19 +233,35 @@ internal fun Modifier.overhang(by: androidx.compose.ui.unit.Dp = 4.dp): Modifier
}
@Composable
internal fun WallFade(modifier: Modifier = Modifier.fillMaxSize().overhang()) {
internal fun WallFade(modifier: Modifier = Modifier.fillMaxSize().overhang(), bottomWhenTall: Boolean = false) {
val colors = MaterialTheme.colorScheme
Box(
modifier.background(
Brush.horizontalGradient(
0f to colors.background.copy(alpha = 0.86f),
0.34f to colors.background.copy(alpha = 0.6f),
0.68f to colors.background.copy(alpha = 0.14f),
1f to colors.background.copy(alpha = 0.04f),
),
),
)
Box(modifier.background(Brush.verticalGradient(0.6f to Color.Transparent, 1f to colors.background.copy(alpha = 0.75f))))
BoxWithConstraints(modifier) {
if (bottomWhenTall && maxHeight > maxWidth) {
// The words sit at the bottom of a tall page, so the art stays clear above them and darkens only behind them.
Box(
Modifier.fillMaxSize().background(
Brush.verticalGradient(
0f to colors.background.copy(alpha = 0.12f),
0.5f to colors.background.copy(alpha = 0.18f),
0.72f to colors.background.copy(alpha = 0.72f),
1f to colors.background.copy(alpha = 0.94f),
),
),
)
} else {
Box(
Modifier.fillMaxSize().background(
Brush.horizontalGradient(
0f to colors.background.copy(alpha = 0.86f),
0.34f to colors.background.copy(alpha = 0.6f),
0.68f to colors.background.copy(alpha = 0.14f),
1f to colors.background.copy(alpha = 0.04f),
),
),
)
Box(Modifier.fillMaxSize().background(Brush.verticalGradient(0.6f to Color.Transparent, 1f to colors.background.copy(alpha = 0.75f))))
}
}
}
@Composable
@@ -387,31 +404,45 @@ private fun CapsuleFan(games: List<Library.SteamGame>) {
transition.animateFloat(0f, 1f, infiniteRepeatable(tween(ms, easing = FastOutSlowInEasing), RepeatMode.Reverse), label = "float")
}
val still = Motion.scale == 0f
val slots = listOf(
val landscape = listOf(
FanSlot(0.54f, 0.14f, 0.62f, -9f),
FanSlot(0.70f, 0.24f, 0.56f, 5f),
FanSlot(0.40f, 0.30f, 0.50f, -17f),
)
// A tall page sizes the cards from its width, so they fit any aspect; heights are fractions of the width.
val portrait = listOf(
FanSlot(0.27f, 0.11f, 0.70f, -9f),
FanSlot(0.55f, 0.19f, 0.64f, 5f),
FanSlot(0.04f, 0.26f, 0.56f, -17f),
)
BoxWithConstraints(
Modifier.fillMaxSize().drawBehind {
drawRect(
Brush.radialGradient(
listOf(pal.signal.copy(alpha = 0.14f), Color.Transparent),
center = Offset(size.width * 0.68f, size.height * 0.45f), radius = size.height * 0.6f,
center = if (size.height > size.width) Offset(size.width * 0.55f, size.height * 0.28f) else Offset(size.width * 0.68f, size.height * 0.45f),
radius = if (size.height > size.width) size.width * 0.9f else size.height * 0.6f,
),
)
},
) {
val radius = with(density) { 14.dp.toPx() }
val tall = maxHeight > maxWidth
val slots = if (tall) portrait else landscape
for (i in games.indices.reversed()) {
val slot = slots[i]
val h = maxHeight * slot.height
val h = if (tall) maxWidth * slot.height else maxHeight * slot.height
val x = if (tall) {
// The lean and the float swing the corners out by about h/2 * sin(angle).
val swing = h * kotlin.math.sin(Math.toRadians(kotlin.math.abs(slot.lean) + 2.0)).toFloat() / 2f
(maxWidth * slot.x).coerceIn(swing, (maxWidth - h * 2f / 3f - swing).coerceAtLeast(swing))
} else maxWidth * slot.x
val v: State<Float> = floats[i]
val look = WallCapsule(artBrush(hueOf(games[i].name)), games[i].art)
val art = look.art?.let { rememberCapsuleArt(it, with(density) { Size((h * 2f / 3f).toPx(), h.toPx()) }, radius) }
Spacer(
Modifier
.offset(x = maxWidth * slot.x, y = maxHeight * slot.y)
.offset(x = x, y = maxHeight * slot.y)
.size(h * 2f / 3f, h)
.graphicsLayer {
val t = if (still) 0f else v.value
+4
View File
@@ -4376,6 +4376,10 @@
<string name="dev_ui_zoo_open">Open</string>
<string name="dev_ui_zoo_show">Show</string>
<string name="dev_ui_zoo_note">Previews change nothing real: nothing is installed, removed or signed out, and the menu\'s switches save nothing. A Library preview stays until you end it from its pill or restart.</string>
<string name="dev_preview_steam_home">Steam home</string>
<string name="dev_preview_steam_none">No games installed</string>
<string name="dev_preview_steam_few">3 games installed</string>
<string name="dev_preview_steam_many">12 games installed</string>
<string name="dev_preview_library">Library</string>
<string name="dev_preview_library_nothing_installed">Nothing installed</string>
<string name="dev_preview_library_signed_out">Signed out of every store</string>
@@ -0,0 +1,84 @@
package com.droiddeck.launcher.ui
import android.text.Spanned
import android.text.TextPaint
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalView
import io.noties.markwon.core.spans.CodeSpan
import io.noties.markwon.ext.tables.TableRowSpan
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotSame
import org.junit.Assert.assertSame
import org.junit.Assert.assertTrue
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
import org.robolectric.annotation.ConscryptMode
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [34], application = android.app.Application::class)
@ConscryptMode(ConscryptMode.Mode.OFF)
class AgentMarkdownPaletteTest {
@get:Rule val compose = createRobolectricComposeRule()
private val reply = "Run `build` first\n\n| Step | Result |\n| --- | --- |\n| Build | [PR](https://github.com/owner/repo/pull/1) |\n\nDone"
private var palette by mutableStateOf(Themes.innerGamer(0f))
private fun View.markdownView(): TextView? = when (this) {
is TextView -> this
is ViewGroup -> (0 until childCount).firstNotNullOfOrNull { getChildAt(it).markdownView() }
else -> null
}
private fun showReply(): TextView {
lateinit var root: View
compose.setContent {
root = LocalView.current
CompositionLocalProvider(LocalPalette provides palette) { AgentMarkdown(reply, Modifier) }
}
compose.waitForIdle()
return requireNotNull(root.markdownView())
}
private fun assertColors(view: TextView, expected: Palette) {
assertEquals(expected.primary2.toArgb(), view.paint.linkColor)
val code = TextPaint()
(view.text as Spanned).getSpans(0, view.text.length, CodeSpan::class.java).single().updateDrawState(code)
assertEquals(expected.surfaceVariant.toArgb(), code.bgColor)
}
@Test fun innerGamerHueStepsRecolorTheReplyWithoutRenderingItAgain() {
val view = showReply()
val rendered = view.tag as Spanned
val rows = rendered.getSpans(0, rendered.length, TableRowSpan::class.java).toSet()
assertTrue(rows.isNotEmpty())
for (hue in listOf(3f, 90f, 180f, 357f)) {
palette = Themes.innerGamer(hue)
compose.waitForIdle()
assertSame(rendered, view.tag)
val current = view.text as Spanned
assertEquals(rows, current.getSpans(0, current.length, TableRowSpan::class.java).toSet())
assertColors(view, palette)
}
}
@Test fun switchingThemesRendersTheReplyInTheNewColors() {
val view = showReply()
for (id in listOf(Themes.GRAPHITE, Themes.WHITE_RED, Themes.INNER_GAMER)) {
val before = view.tag
palette = Themes.byId(id)
compose.waitForIdle()
assertNotSame(before, view.tag)
assertColors(view, palette)
}
}
}
@@ -4,6 +4,8 @@ import android.content.Intent
import android.content.ClipboardManager
import android.text.Selection
import android.text.Spannable
import io.noties.markwon.core.spans.CodeBlockSpan
import io.noties.markwon.core.spans.CodeSpan
import io.noties.markwon.ext.tables.TableRowSpan
import android.graphics.Color
import android.text.Spanned
@@ -23,7 +25,7 @@ import org.robolectric.annotation.Config
@ConscryptMode(ConscryptMode.Mode.OFF)
class AgentMarkdownTest {
private val context get() = RuntimeEnvironment.getApplication()
private val renderer get() = agentMarkdownRenderer(context, Color.BLUE, Color.DKGRAY)
private val renderer get() = agentMarkdownRenderer(context, AgentMarkdownTheme(context).apply { codeBackground = Color.DKGRAY })
private fun Spanned.links() = getSpans(0, length, ClickableSpan::class.java).toList()
@Test fun namedPullRequestLinksKeepTheirLabelsAndOpenAnExternalBrowser() {
@@ -85,27 +87,47 @@ class AgentMarkdownTest {
renderer.render(root)
}
@Test fun colorChangesPreserveSelectionAndRefreshLinkSpans() {
@Test fun rendererChangesPreserveSelectionAndLinksFollowTheViewLinkColor() {
val source = "Read [the PR](https://github.com/owner/repo/pull/1)"
val view = TextView(context).apply { setTextIsSelectable(true) }
val original = renderer
setAgentMarkdown(view, original, original.toMarkdown(source))
Selection.setSelection(view.text as Spannable, 5, 11)
val updated = agentMarkdownRenderer(context, Color.RED, Color.LTGRAY)
val updated = agentMarkdownRenderer(context, AgentMarkdownTheme(context).apply { codeBackground = Color.LTGRAY })
val rendered = updated.toMarkdown(source)
setAgentMarkdown(view, updated, rendered)
assertEquals(5, view.selectionStart)
assertEquals(11, view.selectionEnd)
assertSame(rendered, view.tag)
val paint = android.text.TextPaint()
view.setLinkTextColor(Color.RED)
val paint = android.text.TextPaint().apply { set(view.paint) }
(view.text as Spanned).links().single().updateDrawState(paint)
assertEquals(Color.RED, paint.color)
}
@Test fun codeBackgroundsFollowTheThemeWithoutRenderingAgain() {
val theme = AgentMarkdownTheme(context).apply { codeBackground = Color.DKGRAY }
val rendered = agentMarkdownRenderer(context, theme).toMarkdown("Run `inline`\n\n~~~\nblock\n~~~\n\n indented")
theme.codeBackground = Color.RED
val inline = android.text.TextPaint()
rendered.getSpans(0, rendered.length, CodeSpan::class.java).single().updateDrawState(inline)
assertEquals(Color.RED, inline.bgColor)
val blocks = rendered.getSpans(0, rendered.length, CodeBlockSpan::class.java)
assertEquals(2, blocks.size)
for (block in blocks) {
var filled = 0
val canvas = object : android.graphics.Canvas(android.graphics.Bitmap.createBitmap(10, 10, android.graphics.Bitmap.Config.ARGB_8888)) {
override fun drawRect(rect: android.graphics.Rect, paint: android.graphics.Paint) { filled = paint.color }
}
block.drawLeadingMargin(canvas, android.graphics.Paint(), 0, 1, 0, 5, 10, rendered, 0, 1, true, null)
assertEquals(Color.RED, filled)
}
}
@Test fun reversedSelectionsAndCursorsSurviveColorChangesButNotContentChanges() {
val view = TextView(context).apply { setTextIsSelectable(true) }
val original = renderer
val updated = agentMarkdownRenderer(context, Color.RED, Color.LTGRAY)
val updated = agentMarkdownRenderer(context, AgentMarkdownTheme(context).apply { codeBackground = Color.LTGRAY })
setAgentMarkdown(view, original, original.toMarkdown("A long reply"))
for ((start, end) in listOf(8 to 2, 4 to 4)) {
Selection.setSelection(view.text as Spannable, start, end)