GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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
Filter options
  • apps/web/src/lib
    • elementContext.test.ts
    • elementContext.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/web/src/lib/elementContext.test.ts‎

Copy file name to clipboardExpand all lines: apps/web/src/lib/elementContext.test.ts
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,15 @@ describe("normalizeElementContextSelection", () => {
4343
expect(result!.htmlPreview.endsWith("…")).toBe(true);
4444
expect(result!.styles.endsWith("…")).toBe(true);
4545
});
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+
});
4657
});
Collapse file

‎apps/web/src/lib/elementContext.ts‎

Copy file name to clipboardExpand all lines: apps/web/src/lib/elementContext.ts
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type {
33
PickedElementStackFrame,
44
PreviewAnnotationPayload,
55
} from "@t3tools/contracts";
6+
import { splitsSurrogatePair } from "@t3tools/shared/assistantCitations";
67

78
const ELEMENT_CONTEXT_HTML_PREVIEW_LIMIT = 4000;
89
const ELEMENT_CONTEXT_STYLES_LIMIT = 4000;
@@ -20,7 +21,8 @@ export interface ElementContextSelection {
2021

2122
function truncateString(value: string, limit: number): string {
2223
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)}…`;
2426
}
2527

2628
function normalizeText(value: string): string {

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.