Repository navigation
fix(mobile): three-digit list numbers no longer lose their first digit #19742
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
89a3832
72bdbd0
88d080d
a45f036
94ac683
158f0e8
7eb36bf
d6a2af4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import { describe, expect, it } from "vite-plus/test"; | ||
|
|
||
| import { wideOrderedListMarkerDigits } from "./orderedListMarkers"; | ||
|
|
||
| const numberedList = (count: number, marker = (index: number) => `${index + 1}.`) => | ||
| Array.from({ length: count }, (_, index) => `${marker(index)} item`).join("\n"); | ||
|
|
||
| describe("wideOrderedListMarkerDigits", () => { | ||
| it("returns 0 while every number fits in two digits", () => { | ||
| expect(wideOrderedListMarkerDigits("just a message")).toBe(0); | ||
| expect(wideOrderedListMarkerDigits("- one\n- two")).toBe(0); | ||
| expect(wideOrderedListMarkerDigits(numberedList(99))).toBe(0); | ||
| expect(wideOrderedListMarkerDigits("We shipped it in 2026. More later.")).toBe(0); | ||
| expect(wideOrderedListMarkerDigits("Version 1.2 is out")).toBe(0); | ||
| const withSubLists = Array.from( | ||
| { length: 60 }, | ||
| (_, index) => `${index + 1}. item\n 1. sub\n 2. sub`, | ||
| ).join("\n"); | ||
| expect(wideOrderedListMarkerDigits(withSubLists)).toBe(0); | ||
| }); | ||
|
|
||
| it("measures the widest written number", () => { | ||
| expect(wideOrderedListMarkerDigits(numberedList(130))).toBe(3); | ||
| expect(wideOrderedListMarkerDigits("1000) a")).toBe(4); | ||
| expect(wideOrderedListMarkerDigits("text\r\n\r\n100.\r\n")).toBe(3); | ||
| expect(wideOrderedListMarkerDigits("007. agent")).toBe(0); | ||
| }); | ||
|
|
||
| it("covers lists the renderer numbers itself", () => { | ||
| expect(wideOrderedListMarkerDigits(numberedList(101, () => "1."))).toBe(3); | ||
| }); | ||
|
|
||
| it("finds lists nested in other blocks", () => { | ||
| expect(wideOrderedListMarkerDigits("- 100000. nested")).toBe(6); | ||
| expect(wideOrderedListMarkerDigits("> > 250. quoted")).toBe(3); | ||
| expect(wideOrderedListMarkerDigits("1. a\n\n 100. nested")).toBe(3); | ||
| }); | ||
|
|
||
| it("stays linear on long runs of bullets and spaces", () => { | ||
| expect(wideOrderedListMarkerDigits(`${"- ".repeat(40)}x`)).toBe(0); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| // A line that may start an ordered-list item, including one nested after quote | ||
| // or list markers. Group 1 is everything before the number. Each repeat starts | ||
| // with a marker or `>`, which keeps matching linear. | ||
| const ORDERED_MARKER_LINE = | ||
| /^([ \t>]*(?:(?:[-+*]|\d{1,9}[.)])[ \t]+(?:>[ \t>]*)?)*)(\d{1,9})[.)](?:[ \t\r]|$)/; | ||
| const TOP_LEVEL_PREFIX = /^ {0,3}$/; | ||
|
|
||
| /** | ||
| * Digit count of the widest ordered-list number in `markdown`, when that is | ||
| * three or more digits; otherwise 0. | ||
| * | ||
| * Agents write their list numbers out, so the largest written number covers | ||
| * normal replies. Counting top-level items also covers lists the renderer | ||
| * numbers itself, such as `1.` on every line. Code blocks are not skipped; a | ||
| * stray match there only widens the gutter. | ||
| */ | ||
| export function wideOrderedListMarkerDigits(markdown: string): number { | ||
| let widest = 0; | ||
| let topLevelItems = 0; | ||
| for (const line of markdown.split("\n")) { | ||
| const marker = ORDERED_MARKER_LINE.exec(line); | ||
| if (!marker) continue; | ||
| widest = Math.max(widest, Number(marker[2])); | ||
| if (TOP_LEVEL_PREFIX.test(marker[1]!)) topLevelItems += 1; | ||
| } | ||
| const digits = String(Math.max(widest, topLevelItems)).length; | ||
| return digits >= 3 ? digits : 0; | ||
|
Comment on lines
+22
to
+23
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Restore the effective list-number calculation. For 🤖 Prompt for AI Agents |
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.