CompositionArea: On paste, create emoji Op only if we have data

This commit is contained in:
Scott Nonnenberg 2023-08-28 09:31:24 -07:00 committed by GitHub
parent dc9caa0a99
commit 2532e8902a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -16,6 +16,7 @@ import type { MentionBlot } from './mentions/blot';
import { isNewlineOnlyOp, QuillFormattingStyle } from './formatting/menu';
import { isNotNil } from '../util/isNotNil';
import type { AciString } from '../types/ServiceId';
import { emojiToData } from '../components/emoji/lib';
export type MentionBlotValue = {
aci: AciString;
@ -403,12 +404,15 @@ export const insertEmojiOps = (
// eslint-disable-next-line no-cond-assign
while ((match = re.exec(text))) {
const [emoji] = match;
ops.push({ insert: text.slice(index, match.index), attributes });
ops.push({
insert: { emoji },
attributes: { ...existingAttributes, ...attributes },
});
index = match.index + emoji.length;
const emojiData = emojiToData(emoji);
if (emojiData) {
ops.push({ insert: text.slice(index, match.index), attributes });
ops.push({
insert: { emoji },
attributes: { ...existingAttributes, ...attributes },
});
index = match.index + emoji.length;
}
}
ops.push({ insert: text.slice(index, text.length), attributes });