Skip to content

Commit d1e5044

Browse files
saphidclaude
andauthored
fix(shared): context chip labels no longer split an emoji at the 200-character cap (pingdotgg#29158)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 5fa0d0b commit d1e5044

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

‎packages/shared/src/composerContextReferences.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ describe("labels and reference links", () => {
5959
collectComposerContextReferences(`[${"x".repeat(300)}](t3-context://v1/file/ctx_1)`)[0]
6060
?.label,
6161
).toHaveLength(200);
62+
expect(
63+
collectComposerContextReferences(`[${"x".repeat(199)}😀tail](t3-context://v1/file/ctx_1)`)[0]
64+
?.label,
65+
).toBe("x".repeat(199));
6266
});
6367

6468
it("collects occurrences in document order with offsets, sharing a payload", () => {

‎packages/shared/src/composerContextReferences.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,15 @@ export function parseComposerContextHref(
6767
}
6868

6969
export function sanitizeComposerContextLabel(label: string, kind: ComposerContextKind): string {
70-
const cleaned = label
70+
const normalized = label
7171
.replace(/[[\]\\\r\n]/g, " ")
7272
.replace(/\s+/g, " ")
73-
.trim()
74-
.slice(0, COMPOSER_CONTEXT_LABEL_MAX_CHARS);
73+
.trim();
74+
let end = COMPOSER_CONTEXT_LABEL_MAX_CHARS;
75+
const before = normalized.charCodeAt(end - 1);
76+
const after = normalized.charCodeAt(end);
77+
if (before >= 0xd800 && before <= 0xdbff && after >= 0xdc00 && after <= 0xdfff) end--;
78+
const cleaned = normalized.slice(0, end);
7579
return cleaned.length > 0 ? cleaned : kind;
7680
}
7781

0 commit comments

Comments
 (0)