Improve emoji blot and override clipboard behavior

This commit is contained in:
Sidney Keese 2020-11-06 12:11:18 -08:00 committed by GitHub
parent d4d9688447
commit 91beef7797
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 181 additions and 84 deletions

View file

@ -2,7 +2,7 @@
// SPDX-License-Identifier: AGPL-3.0-only
import Delta from 'quill-delta';
import { LeafBlot } from 'quill';
import { LeafBlot, DeltaOperation } from 'quill';
import Op from 'quill-delta/dist/Op';
import { BodyRangeType } from '../types/Util';
@ -39,6 +39,38 @@ export const isInsertEmojiOp = (op: Op): op is InsertEmojiOp =>
export const isInsertMentionOp = (op: Op): op is InsertMentionOp =>
isSpecificInsertOp(op, 'mention');
export const getTextFromOps = (ops: Array<DeltaOperation>): string =>
ops.reduce((acc, { insert }, index) => {
if (typeof insert === 'string') {
let textToAdd;
switch (index) {
case 0: {
textToAdd = insert.trimLeft();
break;
}
case ops.length - 1: {
textToAdd = insert.trimRight();
break;
}
default: {
textToAdd = insert;
break;
}
}
return acc + textToAdd;
}
if (insert.emoji) {
return acc + insert.emoji;
}
if (insert.mention) {
return `${acc}@${insert.mention.title}`;
}
return acc;
}, '');
export const getTextAndMentionsFromOps = (
ops: Array<Op>
): [string, Array<BodyRangeType>] => {