Skip to content

Commit 7dd06e1

Browse files
committed
fix(web): prevent numbered list markers from being clipped
1 parent 994372b commit 7dd06e1

6 files changed

Lines changed: 30 additions & 16 deletions

File tree

22.3 KB
Loading
22.3 KB
Loading

‎apps/web/src/components/ChatMarkdown.test.tsx‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,13 @@ describe("orderedListGutterStyle", () => {
152152
expect(orderedListGutterStyle(9, undefined)).toBeUndefined();
153153
});
154154

155-
it("leaves the default gutter alone for two-digit lists", () => {
156-
expect(orderedListGutterStyle(99, undefined)).toBeUndefined();
155+
it("widens the gutter for two-digit lists", () => {
156+
expect(orderedListGutterStyle(99, undefined)).toEqual({ "--list-gutter": "3ch" });
157157
});
158158

159-
it("leaves the default gutter alone for a two-digit list that starts above 1", () => {
159+
it("widens the gutter for a two-digit list that starts above 1", () => {
160160
// start=50 + 49 items => last marker is "98", still two digits.
161-
expect(orderedListGutterStyle(49, 50)).toBeUndefined();
161+
expect(orderedListGutterStyle(49, 50)).toEqual({ "--list-gutter": "3ch" });
162162
});
163163

164164
it("widens the gutter once the last marker reaches three digits", () => {
@@ -179,7 +179,7 @@ describe("orderedListGutterStyle", () => {
179179
it("uses the widest marker and includes a negative start's minus sign", () => {
180180
expect(orderedListGutterStyle(1001, -1000)).toEqual({ "--list-gutter": "6ch" });
181181
expect(orderedListGutterStyle(3, -15)).toEqual({ "--list-gutter": "4ch" });
182-
expect(orderedListGutterStyle(3, -5)).toBeUndefined();
182+
expect(orderedListGutterStyle(3, -5)).toEqual({ "--list-gutter": "3ch" });
183183
});
184184

185185
it("treats a missing/zero item count as a single item", () => {

‎apps/web/src/components/ChatMarkdown.tsx‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -217,13 +217,10 @@ function findTaskListMarkerOffset(markdown: string, listItemStart: number): numb
217217
}
218218

219219
/**
220-
* The default `1.25rem` marker gutter (`.chat-markdown ol`) fits markers up to
221-
* two characters wide. Once a marker reaches three characters (item 100+),
222-
* `list-style-position: outside` paints it wider than that gutter and clips
223-
* the leading character against the item's own overflow. Rather than widening
224-
* the gutter for every list, only lists whose widest marker is 3+ characters
225-
* get a wider `--list-gutter`. The width includes a negative marker's minus
226-
* sign.
220+
* The default `1.25rem` marker gutter (`.chat-markdown ol`) fits one-character
221+
* markers. Wider markers can extend past it and get clipped by a collapsed
222+
* message's overflow. Widen the gutter to fit the widest marker, including a
223+
* negative marker's minus sign.
227224
*/
228225
export function orderedListGutterStyle(
229226
itemCount: number,
@@ -233,7 +230,7 @@ export function orderedListGutterStyle(
233230
const firstNumber = Number.isNaN(parsedStart) ? 1 : parsedStart;
234231
const lastNumber = firstNumber + Math.max(itemCount - 1, 0);
235232
const markerWidth = Math.max(String(firstNumber).length, String(lastNumber).length);
236-
if (markerWidth <= 2) return undefined;
233+
if (markerWidth <= 1) return undefined;
237234
return { "--list-gutter": `${markerWidth + 1}ch` };
238235
}
239236

‎apps/web/src/components/chat/MessagesTimeline.test.tsx‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,23 @@ describe("MessagesTimeline", () => {
683683
expect(markup).toContain("rounded-2xl bg-message p-3");
684684
});
685685

686+
it("widens two-digit markers in collapsed user messages", () => {
687+
const markup = renderToStaticMarkup(
688+
<MessagesTimeline
689+
{...buildProps()}
690+
timelineEntries={[
691+
buildUserTimelineEntry(
692+
Array.from({ length: 10 }, (_, index) => `${index + 10}. A`).join("\n"),
693+
),
694+
]}
695+
/>,
696+
);
697+
698+
expect(markup).toContain('<ol start="10" style="--list-gutter:3ch">');
699+
expect(markup).toContain("Show full message");
700+
expect(markup).toContain('data-user-message-collapsed="true"');
701+
});
702+
686703
it("preserves arbitrary XML-like tags and comparisons in rendered user messages", async () => {
687704
const { MessagesTimeline } = await import("./MessagesTimeline");
688705
const markup = renderToStaticMarkup(

‎apps/web/src/index.css‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2156,8 +2156,8 @@ code {
21562156
}
21572157

21582158
.chat-markdown ul {
2159-
/* Reset for nested uls under a widened ol — --list-gutter is an inherited
2160-
custom property, so without this a task-list under a 3+ digit ordered
2159+
/* Reset for nested uls under a widened ol. --list-gutter is an inherited
2160+
custom property, so without this a task-list under a multi-digit ordered
21612161
list would inherit the outer gutter instead of its own default. */
21622162
--list-gutter: 1.25rem;
21632163
padding-left: 1.25rem;
@@ -2166,7 +2166,7 @@ code {
21662166

21672167
/* --list-gutter defaults to the same 1.25rem as .chat-markdown ul, but
21682168
ChatMarkdown's `ol` renderer widens it (via inline style) for lists whose
2169-
widest marker is 3+ characters, so item 100+ isn't clipped by list-style-position:
2169+
widest marker has multiple characters so it isn't clipped by list-style-position:
21702170
outside painting the marker past the padding box. Reset it here too so a
21712171
nested ol without its own widened marker doesn't inherit the outer one. */
21722172
.chat-markdown ol {

0 commit comments

Comments
 (0)