Skip to content

Commit e5193ac

Browse files
authored
fix(web): preview annotation chip labels no longer end in a broken character (pingdotgg#30345)
1 parent b800f99 commit e5193ac

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,14 @@ describe("composerContextRecords", () => {
219219
expect(image).toMatchObject({ attachmentId: "uploaded-image" });
220220
});
221221

222+
it("shortens a long annotation comment label without splitting an emoji", () => {
223+
const record = previewAnnotationContextRecord({
224+
...annotation,
225+
comment: `${"a".repeat(46)}😀 and make the button bigger`,
226+
});
227+
expect(record.label).toBe(`${"a".repeat(46)}…`);
228+
});
229+
222230
it("restores multiple edits on one target without parsing display strings", () => {
223231
const styleChanges = [
224232
...annotation.styleChanges,

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,12 @@ export function pullRequestContextKindLabel(comment: ReviewCommentPresentation):
117117
export function previewAnnotationContextLabel(annotation: PreviewAnnotationPayload): string {
118118
const comment = annotation.comment.trim().replace(/\s+/g, " ");
119119
if (comment) {
120-
return comment.length > PREVIEW_LABEL_MAX_CHARS
121-
? `${comment.slice(0, PREVIEW_LABEL_MAX_CHARS - 1)}…`
122-
: comment;
120+
if (comment.length <= PREVIEW_LABEL_MAX_CHARS) return comment;
121+
let end = PREVIEW_LABEL_MAX_CHARS - 1;
122+
const previous = comment.charCodeAt(end - 1);
123+
const next = comment.charCodeAt(end);
124+
if (previous >= 0xd800 && previous <= 0xdbff && next >= 0xdc00 && next <= 0xdfff) end -= 1;
125+
return `${comment.slice(0, end)}…`;
123126
}
124127
return annotation.pageTitle?.trim() || "Preview annotation";
125128
}

0 commit comments

Comments
 (0)