GeezerVison is showing github.com — fix(web): element context preview no longer ends in a split surrogate… · orbitingflea/t3code@4e6b1fa
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: apps/web/src/lib/elementContext.test.ts +11Lines changed: 11 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -43,4 +43,15 @@ describe("normalizeElementContextSelection", () => { |
43 | 43 | expect(result!.htmlPreview.endsWith("…")).toBe(true); |
44 | 44 | expect(result!.styles.endsWith("…")).toBe(true); |
45 | 45 | }); |
| 46 | + |
| 47 | + it("drops a straddling surrogate pair instead of leaving a lone high surrogate", () => { |
| 48 | + const prefix = `${"a".repeat(3997)}b`; |
| 49 | + const straddling = `${prefix}🚀tail`; |
| 50 | + const result = normalizeElementContextSelection( |
| 51 | + makePayload({ htmlPreview: straddling, styles: straddling }), |
| 52 | + ); |
| 53 | + expect(result).not.toBeNull(); |
| 54 | + expect(result!.htmlPreview).toBe(`${prefix}…`); |
| 55 | + expect(result!.styles).toBe(`${prefix}…`); |
| 56 | + }); |
46 | 57 | }); |
Collapse file
Copy file name to clipboardExpand all lines: apps/web/src/lib/elementContext.ts +3-1Lines changed: 3 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -3,6 +3,7 @@ import type { |
3 | 3 | PickedElementStackFrame, |
4 | 4 | PreviewAnnotationPayload, |
5 | 5 | } from "@t3tools/contracts"; |
| 6 | +import { splitsSurrogatePair } from "@t3tools/shared/assistantCitations"; |
6 | 7 |
|
7 | 8 | const ELEMENT_CONTEXT_HTML_PREVIEW_LIMIT = 4000; |
8 | 9 | const ELEMENT_CONTEXT_STYLES_LIMIT = 4000; |
@@ -20,7 +21,8 @@ export interface ElementContextSelection { |
20 | 21 |
|
21 | 22 | function truncateString(value: string, limit: number): string { |
22 | 23 | if (value.length <= limit) return value; |
23 | | - return `${value.slice(0, Math.max(0, limit - 1))}…`; |
| 24 | + const cut = Math.max(0, limit - 1); |
| 25 | + return `${value.slice(0, splitsSurrogatePair(value, cut) ? cut - 1 : cut)}…`; |
24 | 26 | } |
25 | 27 |
|
26 | 28 | function normalizeText(value: string): string { |
|