fix: correctly identify emoticons (#10108)
Signed-off-by: Adarsh Singh <thakurluckysinghbrh@gmail.com>
This commit is contained in:
parent
42692820c7
commit
f24db71753
2 changed files with 50 additions and 17 deletions
|
@ -191,16 +191,19 @@ export default class BasicMessageEditor extends React.Component<IProps, IState>
|
|||
public replaceEmoticon(caretPosition: DocumentPosition, regex: RegExp): number {
|
||||
const { model } = this.props;
|
||||
const range = model.startRange(caretPosition);
|
||||
// expand range max 8 characters backwards from caretPosition,
|
||||
// expand range max 9 characters backwards from caretPosition,
|
||||
// as a space to look for an emoticon
|
||||
let n = 8;
|
||||
let n = 9;
|
||||
range.expandBackwardsWhile((index, offset) => {
|
||||
const part = model.parts[index];
|
||||
n -= 1;
|
||||
return n >= 0 && [Type.Plain, Type.PillCandidate, Type.Newline].includes(part.type);
|
||||
});
|
||||
const emoticonMatch = regex.exec(range.text);
|
||||
if (emoticonMatch) {
|
||||
// ignore matches at start of proper substrings
|
||||
// so xd will not match if the string was "mixd 123456"
|
||||
// and we are lookinh at xd 123456 part of the string
|
||||
if (emoticonMatch && (n >= 0 || emoticonMatch.index !== 0)) {
|
||||
const query = emoticonMatch[1].replace("-", "");
|
||||
// try both exact match and lower-case, this means that xd won't match xD but :P will match :p
|
||||
const data = EMOTICON_TO_EMOJI.get(query) || EMOTICON_TO_EMOJI.get(query.toLowerCase());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue