Skip to content

Commit beaea4d

Browse files
committed
fix(shared): long assistant quote chips no longer end in a broken character
assistantCitationLabel cut a quote or its comment at 64 UTF-16 code units. When an emoji straddled the cut, the label kept only its high surrogate, so it ended in a replacement character before the ellipsis. That shows in the quote chip of a sent message on a desktop-width window, in the chip's screen-reader labels and in the text find-in-thread searches. The composer chip clips its label to one 16em line, so the broken end never shows there. The cut now steps back one unit when it would land between a high and a low surrogate, the same check #29158 added to context chip labels. Bug: a long assistant quote chip ends in a broken character when an emoji sits at the cut
1 parent b8523ed commit beaea4d

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

‎packages/shared/src/assistantCitations.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,14 @@ export function parseAssistantCitationHref(href: string): AssistantCitation | nu
9898

9999
export function assistantCitationLabel(citation: AssistantCitation): string {
100100
const preview = (citation.comment?.trim() || citation.text).replace(/\s+/g, " ");
101-
return preview.length > 64 ? `${preview.slice(0, 64)}…` : preview;
101+
if (preview.length <= 64) return preview;
102+
let end = 64;
103+
const previous = preview.charCodeAt(end - 1);
104+
const next = preview.charCodeAt(end);
105+
if (previous >= 0xd800 && previous <= 0xdbff && next >= 0xdc00 && next <= 0xdfff) {
106+
end -= 1;
107+
}
108+
return `${preview.slice(0, end)}…`;
102109
}
103110

104111
export function serializeAssistantCitation(citation: AssistantCitation): string {

0 commit comments

Comments
 (0)