Skip to content

Commit 2fb73bd

Browse files
elias6jamiebuilds-signal
authored andcommitted
Fix link previews for messages with emojis
1 parent fd9f7a9 commit 2fb73bd

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

ts/test-node/types/LinkPreview_test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,24 @@ describe('Link previews', () => {
116116
assert.deepEqual(expected, actual);
117117
});
118118

119+
it('returns all links after emojis with spaces in between, if a caretLocation is provided', () => {
120+
const text = '😎 https://github.com/signalapp/Signal-Desktop';
121+
122+
const expected = ['https://github.com/signalapp/Signal-Desktop'];
123+
124+
const actual = findLinks(text, 45);
125+
assert.deepEqual(expected, actual);
126+
});
127+
128+
it('returns all links after a complex emoji, if a caretLocation is provided', () => {
129+
const text = '👨‍👩‍👦 https://github.com/signalapp/Signal-Desktop';
130+
131+
const expected = ['https://github.com/signalapp/Signal-Desktop'];
132+
133+
const actual = findLinks(text, 45);
134+
assert.deepEqual(expected, actual);
135+
});
136+
119137
it('includes all links if cursor is not in a link', () => {
120138
const text =
121139
'Check out this link: https://github.com/signalapp/Signal-Desktop\nAnd this one too: https://github.com/signalapp/Signal-Android';

ts/types/LinkPreview.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import LinkifyIt from 'linkify-it';
1010

1111
import { maybeParseUrl } from '../util/url.js';
1212
import { replaceEmojiWithSpaces } from '../util/emoji.js';
13+
import { count } from '../util/grapheme.js';
1314

1415
import type { AttachmentWithHydratedData } from './Attachment.js';
1516
import {
@@ -167,7 +168,7 @@ export function findLinks(text: string, caretLocation?: number): Array<string> {
167168
}
168169

169170
const haveCaretLocation = isNumber(caretLocation);
170-
const textLength = text ? text.length : 0;
171+
const textLength = count(text || '');
171172

172173
const matches = linkify.match(text ? replaceEmojiWithSpaces(text) : '') || [];
173174
return compact(

0 commit comments

Comments
 (0)