fix(web): prevent two-digit list markers from being clipped (#9101)
Co-authored-by: shivam <[email protected]>
This commit is contained in:
1 parent
f14f41b894
commit
70cd258d8a
3 files changed
+13
-16
No files matched your search
@@ -360,13 +360,13 @@ describe("orderedListGutterStyle", () => {
|
||||
expect(orderedListGutterStyle(9, undefined)).toBeUndefined();
|
||||
});
|
||||
|
||||
it("leaves the default gutter alone for two-digit lists", () => {
|
||||
expect(orderedListGutterStyle(99, undefined)).toBeUndefined();
|
||||
it("widens the gutter for two-digit lists", () => {
|
||||
expect(orderedListGutterStyle(99, undefined)).toEqual({ "--list-gutter": "3ch" });
|
||||
});
|
||||
|
||||
it("leaves the default gutter alone for a two-digit list that starts above 1", () => {
|
||||
it("widens the gutter for a two-digit list that starts above 1", () => {
|
||||
// start=50 + 49 items => last marker is "98", still two digits.
|
||||
expect(orderedListGutterStyle(49, 50)).toBeUndefined();
|
||||
expect(orderedListGutterStyle(49, 50)).toEqual({ "--list-gutter": "3ch" });
|
||||
});
|
||||
|
||||
it("widens the gutter once the last marker reaches three digits", () => {
|
||||
@@ -387,7 +387,7 @@ describe("orderedListGutterStyle", () => {
|
||||
it("uses the widest marker and includes a negative start's minus sign", () => {
|
||||
expect(orderedListGutterStyle(1001, -1000)).toEqual({ "--list-gutter": "6ch" });
|
||||
expect(orderedListGutterStyle(3, -15)).toEqual({ "--list-gutter": "4ch" });
|
||||
expect(orderedListGutterStyle(3, -5)).toBeUndefined();
|
||||
expect(orderedListGutterStyle(3, -5)).toEqual({ "--list-gutter": "3ch" });
|
||||
});
|
||||
|
||||
it("treats a missing/zero item count as a single item", () => {
|
||||
|
||||
@@ -328,13 +328,10 @@ function findTaskListMarkerOffset(markdown: string, listItemStart: number): numb
|
||||
}
|
||||
|
||||
/**
|
||||
* The default `1.25rem` marker gutter (`.chat-markdown ol`) fits markers up to
|
||||
* two characters wide. Once a marker reaches three characters (item 100+),
|
||||
* `list-style-position: outside` paints it wider than that gutter and clips
|
||||
* the leading character against the item's own overflow. Rather than widening
|
||||
* the gutter for every list, only lists whose widest marker is 3+ characters
|
||||
* get a wider `--list-gutter`. The width includes a negative marker's minus
|
||||
* sign.
|
||||
* The default `1.25rem` marker gutter (`.chat-markdown ol`) fits one-character
|
||||
* markers. Wider markers can extend past it and get clipped by a collapsed
|
||||
* message's overflow. Widen the gutter to fit the widest marker, including a
|
||||
* negative marker's minus sign.
|
||||
*/
|
||||
export function orderedListGutterStyle(
|
||||
itemCount: number,
|
||||
@@ -344,7 +341,7 @@ export function orderedListGutterStyle(
|
||||
const firstNumber = Number.isNaN(parsedStart) ? 1 : parsedStart;
|
||||
const lastNumber = firstNumber + Math.max(itemCount - 1, 0);
|
||||
const markerWidth = Math.max(String(firstNumber).length, String(lastNumber).length);
|
||||
if (markerWidth <= 2) return undefined;
|
||||
if (markerWidth <= 1) return undefined;
|
||||
return { "--list-gutter": `${markerWidth + 1}ch` };
|
||||
}
|
||||
|
||||
|
||||
@@ -1643,8 +1643,8 @@ code {
|
||||
}
|
||||
|
||||
.chat-markdown ul {
|
||||
/* Reset for nested uls under a widened ol — --list-gutter is an inherited
|
||||
custom property, so without this a task-list under a 3+ digit ordered
|
||||
/* Reset for nested uls under a widened ol. --list-gutter is an inherited
|
||||
custom property, so without this a task-list under a multi-digit ordered
|
||||
list would inherit the outer gutter instead of its own default. */
|
||||
--list-gutter: 1.25rem;
|
||||
padding-left: 1.25rem;
|
||||
@@ -1653,7 +1653,7 @@ code {
|
||||
|
||||
/* --list-gutter defaults to the same 1.25rem as .chat-markdown ul, but
|
||||
ChatMarkdown's `ol` renderer widens it (via inline style) for lists whose
|
||||
widest marker is 3+ characters, so item 100+ isn't clipped by list-style-position:
|
||||
widest marker has multiple characters so it isn't clipped by list-style-position:
|
||||
outside painting the marker past the padding box. Reset it here too so a
|
||||
nested ol without its own widened marker doesn't inherit the outer one. */
|
||||
.chat-markdown ol {
|
||||
|
||||
Reference in new issue
Block a user