fix regional emojis converted to flags (#9294)
Co-authored-by: grimhilt <grimhilt@users.noreply.github.com> Co-authored-by: Michael Telatynski <7t3chguy@gmail.com> Co-authored-by: Faye Duxovni <duxovni@duxovni.org> Co-authored-by: Faye Duxovni <fayed@element.io> Fixes https://github.com/vector-im/element-web/issues/19000
This commit is contained in:
parent
262c2fcff2
commit
5a08859e37
4 changed files with 71 additions and 16 deletions
|
@ -27,6 +27,8 @@ import defaultDispatcher from "../dispatcher/dispatcher";
|
|||
import { Action } from "../dispatcher/actions";
|
||||
import SettingsStore from "../settings/SettingsStore";
|
||||
|
||||
const REGIONAL_EMOJI_SEPARATOR = String.fromCodePoint(0x200b);
|
||||
|
||||
interface ISerializedPart {
|
||||
type: Type.Plain | Type.Newline | Type.Emoji | Type.Command | Type.PillCandidate;
|
||||
text: string;
|
||||
|
@ -209,9 +211,13 @@ abstract class PlainBasePart extends BasePart {
|
|||
return false;
|
||||
}
|
||||
|
||||
// or split if the previous character is a space
|
||||
// or split if the previous character is a space or regional emoji separator
|
||||
// or if it is a + and this is a :
|
||||
return this._text[offset - 1] !== " " && (this._text[offset - 1] !== "+" || chr !== ":");
|
||||
return (
|
||||
this._text[offset - 1] !== " " &&
|
||||
this._text[offset - 1] !== REGIONAL_EMOJI_SEPARATOR &&
|
||||
(this._text[offset - 1] !== "+" || chr !== ":")
|
||||
);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -626,8 +632,13 @@ export class PartCreator {
|
|||
return new UserPillPart(userId, displayName, member);
|
||||
}
|
||||
|
||||
private static isRegionalIndicator(c: string): boolean {
|
||||
const codePoint = c.codePointAt(0) ?? 0;
|
||||
return codePoint != 0 && c.length == 2 && 0x1f1e6 <= codePoint && codePoint <= 0x1f1ff;
|
||||
}
|
||||
|
||||
public plainWithEmoji(text: string): (PlainPart | EmojiPart)[] {
|
||||
const parts = [];
|
||||
const parts: (PlainPart | EmojiPart)[] = [];
|
||||
let plainText = "";
|
||||
|
||||
// We use lodash's grapheme splitter to avoid breaking apart compound emojis
|
||||
|
@ -638,6 +649,9 @@ export class PartCreator {
|
|||
plainText = "";
|
||||
}
|
||||
parts.push(this.emoji(char));
|
||||
if (PartCreator.isRegionalIndicator(text)) {
|
||||
parts.push(this.plain(REGIONAL_EMOJI_SEPARATOR));
|
||||
}
|
||||
} else {
|
||||
plainText += char;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue