1
mirror of https://github.com/jakejarvis/imagemoji.git synced 2025-04-25 18:05:21 -04:00

fix text nodes disappearing before parsed emoji

This commit is contained in:
Jake Jarvis 2021-11-10 10:37:12 -05:00
parent c7310c5cb0
commit 1f863e5e64
Signed by: jake
GPG Key ID: 2B0C9CF251E69A39

View File

@ -101,28 +101,29 @@ const getAllTextNodes = function (node: Node, allText: Node[] = []): Node[] {
* @return same generic node with emoji in place, if any.
*/
const parseNode = function (node: Node, srcGenerator: (icon: string) => string): Node {
const allText = getAllTextNodes(node);
const allText = getAllTextNodes(node, []);
let { length } = allText;
while (length--) {
let modified = false;
const fragment = document.createDocumentFragment();
const subnode = allText[length];
const text = subnode.nodeValue || "";
let match: RegExpExecArray | null;
let modified = false;
let i = 0;
while ((match = regex.exec(text))) {
const { index } = match;
const rawEmoji = match[0]; // eslint-disable-line prefer-destructuring
const icon = toCodePoint(rawEmoji);
const src = srcGenerator(icon);
i = index + rawEmoji.length;
if (index !== i) {
fragment.appendChild(createText(text.slice(i, index), true));
}
const rawEmoji = match[0]; // eslint-disable-line prefer-destructuring
const icon = toCodePoint(rawEmoji);
const src = srcGenerator(icon);
i = index + rawEmoji.length;
if (icon && src) {
const img = new Image();
img.setAttribute("draggable", "false");