Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

fix(mobile): keep ordered lists inside user bubbles (#6154)

Nick Anisimove1378a1f4d6a
diff --git a/apps/mobile/src/features/threads/ThreadFeed.tsx b/apps/mobile/src/features/threads/ThreadFeed.tsx
index 0bd57799f..874c31249 100644
--- a/apps/mobile/src/features/threads/ThreadFeed.tsx
+++ b/apps/mobile/src/features/threads/ThreadFeed.tsx
@@ -104,6 +104,10 @@ import { useMarkdownCodeHighlight } from "./markdownCodeHighlightState";
import { useAssetUrl } from "../../state/assets";
import { resolveWorkspaceRelativeFilePath } from "../files/filePath";
+const WIDE_MARKDOWN_BLOCK_OPTIONS = {
+ includeOrderedLists: Platform.OS === "android",
+} as const;
+
const MESSAGE_TIME_FORMATTER = new Intl.DateTimeFormat(undefined, {
hour: "numeric",
minute: "2-digit",
@@ -888,7 +892,7 @@ function renderFeedEntry(
// children during the unclamped pass and never moves them once the width
// is clamped, so the paragraphs around the block end up drawn on top of
// each other. Pinning the width removes that pass.
- const hasWideBlock = hasWideMarkdownBlock(message.text);
+ const hasWideBlock = hasWideMarkdownBlock(message.text, WIDE_MARKDOWN_BLOCK_OPTIONS);
const assistantTurnStillInProgress =
message.role === "assistant" &&
props.unsettledTurnId !== null &&
diff --git a/apps/mobile/src/lib/wideMarkdownBlocks.test.ts b/apps/mobile/src/lib/wideMarkdownBlocks.test.ts
index 9f0bcaee3..b0af9434c 100644
--- a/apps/mobile/src/lib/wideMarkdownBlocks.test.ts
+++ b/apps/mobile/src/lib/wideMarkdownBlocks.test.ts
@@ -17,6 +17,30 @@ describe("hasWideMarkdownBlock", () => {
expect(hasWideMarkdownBlock(" ```\ncode\n```")).toBe(true);
});
+ it("detects top-level and blockquoted ordered-list markers", () => {
+ expect(hasWideMarkdownBlock("1. One\n2. Two\n3. Three\n4. Four\n5. Five")).toBe(true);
+ expect(hasWideMarkdownBlock("before\n3) Three")).toBe(true);
+ expect(hasWideMarkdownBlock("> 1. One\n> 2. Two")).toBe(true);
+ expect(hasWideMarkdownBlock("> > 3) Three")).toBe(true);
+ });
+
+ it("detects nested ordered lists without treating indented code as a list", () => {
+ expect(hasWideMarkdownBlock("- Parent\n 1. Child\n 2. Child")).toBe(true);
+ expect(hasWideMarkdownBlock("> - Parent\n> 1. Child")).toBe(true);
+ expect(hasWideMarkdownBlock(" 1. indented code")).toBe(false);
+ expect(hasWideMarkdownBlock(" - code-like bullet\n 1. indented code")).toBe(false);
+ });
+
+ it("can limit ordered-list width pinning to Android", () => {
+ const orderedList = "1. One\n2. Two";
+ expect(hasWideMarkdownBlock(orderedList, { includeOrderedLists: true })).toBe(true);
+ expect(hasWideMarkdownBlock(orderedList, { includeOrderedLists: false })).toBe(false);
+ expect(hasWideMarkdownBlock("```\ncode\n```", { includeOrderedLists: false })).toBe(true);
+ expect(hasWideMarkdownBlock("| a | b |\n| --- | --- |", { includeOrderedLists: false })).toBe(
+ true,
+ );
+ });
+
it("detects GFM tables", () => {
expect(hasWideMarkdownBlock("| a | b |\n| --- | --- |\n| 1 | 2 |")).toBe(true);
expect(hasWideMarkdownBlock("a | b\n:-- | --:\n1 | 2")).toBe(true);
diff --git a/apps/mobile/src/lib/wideMarkdownBlocks.ts b/apps/mobile/src/lib/wideMarkdownBlocks.ts
index 801d826df..3c7279fc4 100644
--- a/apps/mobile/src/lib/wideMarkdownBlocks.ts
+++ b/apps/mobile/src/lib/wideMarkdownBlocks.ts
@@ -1,9 +1,10 @@
/**
- * Detects markdown that the JS renderer draws as a standalone block View
- * wrapping a horizontal ScrollView — fenced code blocks and GFM tables.
+ * Detects markdown that the JS renderer draws as a block requiring a definite
+ * user-bubble width — fenced code blocks, GFM tables, and ordered lists.
*
- * Those blocks report an intrinsic width equal to their widest line, which is
- * effectively unbounded. A user bubble sizes itself from its content
+ * Fenced code blocks and tables report an intrinsic width equal to their
+ * widest line, which is effectively unbounded. A user bubble sizes itself
+ * from its content
* (`maxWidth` with no `width`), so Android lays the bubble's children out
* during the unclamped intrinsic pass — where the surrounding paragraphs
* collapse to a single line — and never repositions them once the width is
@@ -12,12 +13,57 @@
* intrinsic pass entirely, which is the same reason review-comment bubbles
* already carry an explicit width.
*
- * Indented (four-space) code blocks are deliberately not detected: they are
- * vanishingly rare in chat input and the check would fire on ordinary nested
- * list continuations.
+ * Ordered lists hit the same Android layout bug because each item contains a
+ * flexing content column inside a shrink-to-fit row.
+ *
+ * A four-space ordered marker is only treated as a list when the preceding
+ * non-empty line is a less-indented list item. This keeps standalone indented
+ * code out of the heuristic while covering nested lists.
*/
const FENCED_CODE_BLOCK = /^ {0,3}(?:```|~~~)/m;
+// Trades some precision for a simple check, favoring false positives over false
+// negatives: list-shaped paragraph may get a wider bubble
+const ORDERED_LIST_ITEM = /^ {0,3}\d{1,9}[.)](?:[ \t]+|$)/;
+const INDENTED_ORDERED_LIST_ITEM = /^( {4,})\d{1,9}[.)](?:[ \t]+|$)/;
+const ANY_LIST_ITEM = /^( *)(?:[-+*]|\d{1,9}[.)])(?:[ \t]+|$)/;
+const BLOCKQUOTE_PREFIX = /^ {0,3}>[ \t]?/;
+
+export interface WideMarkdownBlockOptions {
+ readonly includeOrderedLists?: boolean;
+}
+
+function stripBlockquotePrefixes(line: string): string {
+ let content = line;
+ while (BLOCKQUOTE_PREFIX.test(content)) {
+ content = content.replace(BLOCKQUOTE_PREFIX, "");
+ }
+ return content;
+}
+
+function hasOrderedListItem(text: string): boolean {
+ let previousNonEmptyLine: string | null = null;
+
+ for (const rawLine of text.split("\n")) {
+ const line = stripBlockquotePrefixes(rawLine);
+ if (ORDERED_LIST_ITEM.test(line)) {
+ return true;
+ }
+
+ const nestedMatch = INDENTED_ORDERED_LIST_ITEM.exec(line);
+ const parentMatch =
+ previousNonEmptyLine === null ? null : ANY_LIST_ITEM.exec(previousNonEmptyLine);
+ if (nestedMatch && parentMatch && parentMatch[1].length < nestedMatch[1].length) {
+ return true;
+ }
+
+ if (line.trim().length > 0) {
+ previousNonEmptyLine = line;
+ }
+ }
+
+ return false;
+}
function isTableDelimiterRow(line: string): boolean {
const trimmed = line.trim();
@@ -27,10 +73,16 @@ function isTableDelimiterRow(line: string): boolean {
return /^[|\-: \t]+$/.test(trimmed);
}
-export function hasWideMarkdownBlock(text: string): boolean {
+export function hasWideMarkdownBlock(
+ text: string,
+ options: WideMarkdownBlockOptions = {},
+): boolean {
if (FENCED_CODE_BLOCK.test(text)) {
return true;
}
+ if (options.includeOrderedLists !== false && hasOrderedListItem(text)) {
+ return true;
+ }
if (!text.includes("|")) {
return false;
}