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:
parent
c7310c5cb0
commit
1f863e5e64
@ -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");
|
||||
|
Loading…
x
Reference in New Issue
Block a user