Skip to content

Commit 4c16851

Browse files
committed
fix(web): preview annotation chip labels no longer end in a broken character
A preview annotation's context chip takes its label from the comment, cut at 47 UTF-16 code units before the shared label sanitizer runs. An emoji straddling that cut left a lone high surrogate before the ellipsis, so the chip, the record sent with the message and a thread title seeded from the annotation all showed a replacement character. The cut now steps back one unit when it would split a surrogate pair, the check #29158 added to the shared context chip label cap. The 48-character limit and labels without a split emoji are unchanged. Bug: a preview annotation chip label ends in a broken character when an emoji sits at the cut
1 parent 941f304 commit 4c16851

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,12 @@ export function pullRequestContextKindLabel(comment: ReviewCommentPresentation):
110110
export function previewAnnotationContextLabel(annotation: PreviewAnnotationPayload): string {
111111
const comment = annotation.comment.trim().replace(/\s+/g, " ");
112112
if (comment) {
113-
return comment.length > PREVIEW_LABEL_MAX_CHARS
114-
? `${comment.slice(0, PREVIEW_LABEL_MAX_CHARS - 1)}…`
115-
: comment;
113+
if (comment.length <= PREVIEW_LABEL_MAX_CHARS) return comment;
114+
let end = PREVIEW_LABEL_MAX_CHARS - 1;
115+
const previous = comment.charCodeAt(end - 1);
116+
const next = comment.charCodeAt(end);
117+
if (previous >= 0xd800 && previous <= 0xdbff && next >= 0xdc00 && next <= 0xdfff) end -= 1;
118+
return `${comment.slice(0, end)}…`;
116119
}
117120
return annotation.pageTitle?.trim() || "Preview annotation";
118121
}

0 commit comments

Comments
 (0)