fix(mobile): stop indented code overflowing Android chat bubbles (#9347)

This commit is contained in:
Adamulek123 authored and GitHub committed 2026-09-03 01:30:10 -04:00
1 parent f6c04c552c
commit 1575ada305
2 files changed
+43 -6

No files matched your search

+16 -4
View File
@@ -17,6 +17,20 @@ describe("hasWideMarkdownBlock", () => {
expect(hasWideMarkdownBlock(" ```\ncode\n```")).toBe(true);
});
it("detects indented code blocks", () => {
const prompt = 'before\n\n def search(x):\n return x\n\n"""\n\nafter';
expect(hasWideMarkdownBlock(prompt)).toBe(true);
expect(hasWideMarkdownBlock("before\n\n\treturn x\n\nafter")).toBe(true);
expect(hasWideMarkdownBlock("before\n\n \treturn x\n\nafter")).toBe(true);
expect(hasWideMarkdownBlock("> return x")).toBe(true);
expect(hasWideMarkdownBlock("> > \treturn x")).toBe(true);
expect(hasWideMarkdownBlock(" 1. indented code")).toBe(true);
expect(hasWideMarkdownBlock(" - code-like bullet")).toBe(true);
expect(hasWideMarkdownBlock("before\n not code\nafter")).toBe(false);
expect(hasWideMarkdownBlock("before\n \nafter")).toBe(false);
expect(hasWideMarkdownBlock("before\n \t\nafter")).toBe(false);
});
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);
@@ -24,11 +38,9 @@ describe("hasWideMarkdownBlock", () => {
expect(hasWideMarkdownBlock("> > 3) Three")).toBe(true);
});
it("detects nested ordered lists without treating indented code as a list", () => {
it("detects nested ordered lists", () => {
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", () => {
@@ -46,7 +58,7 @@ describe("hasWideMarkdownBlock", () => {
expect(hasWideMarkdownBlock(" > quoted", { includeBlockquotes: true })).toBe(true);
expect(hasWideMarkdownBlock("> quoted")).toBe(false);
expect(hasWideMarkdownBlock("prose > quoted", { includeBlockquotes: true })).toBe(false);
expect(hasWideMarkdownBlock(" > indented code", { includeBlockquotes: true })).toBe(false);
expect(hasWideMarkdownBlock(" > indented code", { includeBlockquotes: true })).toBe(true);
});
it("detects GFM tables", () => {
+27 -2
View File
@@ -1,7 +1,7 @@
/**
* Detects markdown that the renderer draws as a block requiring a definite
* user-bubble width: fenced code blocks, GFM tables, ordered lists, and
* blockquotes when requested by the caller.
* user-bubble width: fenced and indented code blocks, GFM tables, ordered
* lists, and blockquotes when requested by the caller.
*
* Fenced code blocks and tables report an intrinsic width equal to their
* widest line, which is effectively unbounded. A user bubble sizes itself
@@ -43,6 +43,28 @@ function stripBlockquotePrefixes(line: string): string {
return content;
}
function hasIndentedCodeBlock(text: string): boolean {
return text.split("\n").some((rawLine) => {
const line = stripBlockquotePrefixes(rawLine);
let column = 0;
let index = 0;
// Markdown tabs advance to the next four-column stop.
while (index < line.length) {
if (line[index] === " ") {
column += 1;
} else if (line[index] === "\t") {
column += 4 - (column % 4);
} else {
break;
}
index += 1;
}
return column >= 4 && index < line.length && line[index] !== "\r";
});
}
function hasBlockquote(text: string): boolean {
return text.split("\n").some((line) => BLOCKQUOTE_PREFIX.test(line));
}
@@ -89,6 +111,9 @@ export function hasWideMarkdownBlock(
if (options.includeBlockquotes === true && hasBlockquote(text)) {
return true;
}
if (hasIndentedCodeBlock(text)) {
return true;
}
if (options.includeOrderedLists !== false && hasOrderedListItem(text)) {
return true;
}