Make emoji text matching case-insensitive

See [#5186][5186].

[5186]: https://github.com/signalapp/Signal-Desktop/pull/5186
This commit is contained in:
Quentin Hibon 2021-09-17 11:21:33 -05:00 committed by Evan Hahn
parent 51d85e58eb
commit 756af78d57
2 changed files with 7 additions and 10 deletions

View file

@ -104,7 +104,7 @@ export class EmojiCompletion {
const range = this.quill.getSelection(); const range = this.quill.getSelection();
const [blot, index] = this.quill.getLeaf(range ? range.index : -1); const [blot, index] = this.quill.getLeaf(range ? range.index : -1);
return getBlotTextPartitions(blot, index); return getBlotTextPartitions(blot.text, index);
} }
onSelectionChange(): void { onSelectionChange(): void {

View file

@ -93,17 +93,14 @@ export const getTextAndMentionsFromOps = (
}; };
export const getBlotTextPartitions = ( export const getBlotTextPartitions = (
blot: LeafBlot, blotText: string | undefined,
index: number index: number
): [string, string] => { ): [string, string] => {
if (blot !== undefined && blot.text !== undefined) { const lowerCaseBlotText = (blotText || '').toLowerCase();
const leftLeafText = blot.text.substr(0, index); const leftLeafText = lowerCaseBlotText.substr(0, index);
const rightLeafText = blot.text.substr(index); const rightLeafText = lowerCaseBlotText.substr(index);
return [leftLeafText, rightLeafText]; return [leftLeafText, rightLeafText];
}
return ['', ''];
}; };
export const matchBlotTextPartitions = ( export const matchBlotTextPartitions = (
@ -112,7 +109,7 @@ export const matchBlotTextPartitions = (
leftRegExp: RegExp, leftRegExp: RegExp,
rightRegExp?: RegExp rightRegExp?: RegExp
): Array<RegExpMatchArray | null> => { ): Array<RegExpMatchArray | null> => {
const [leftText, rightText] = getBlotTextPartitions(blot, index); const [leftText, rightText] = getBlotTextPartitions(blot.text, index);
const leftMatch = leftRegExp.exec(leftText); const leftMatch = leftRegExp.exec(leftText);
let rightMatch = null; let rightMatch = null;