mirror of
https://github.com/jakejarvis/imagemoji.git
synced 2025-04-28 07:00:30 -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.
|
* @return same generic node with emoji in place, if any.
|
||||||
*/
|
*/
|
||||||
const parseNode = function (node: Node, srcGenerator: (icon: string) => string): Node {
|
const parseNode = function (node: Node, srcGenerator: (icon: string) => string): Node {
|
||||||
const allText = getAllTextNodes(node);
|
const allText = getAllTextNodes(node, []);
|
||||||
let { length } = allText;
|
let { length } = allText;
|
||||||
|
|
||||||
while (length--) {
|
while (length--) {
|
||||||
|
let modified = false;
|
||||||
const fragment = document.createDocumentFragment();
|
const fragment = document.createDocumentFragment();
|
||||||
const subnode = allText[length];
|
const subnode = allText[length];
|
||||||
const text = subnode.nodeValue || "";
|
const text = subnode.nodeValue || "";
|
||||||
let match: RegExpExecArray | null;
|
let match: RegExpExecArray | null;
|
||||||
let modified = false;
|
|
||||||
let i = 0;
|
let i = 0;
|
||||||
|
|
||||||
while ((match = regex.exec(text))) {
|
while ((match = regex.exec(text))) {
|
||||||
const { index } = match;
|
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) {
|
if (index !== i) {
|
||||||
fragment.appendChild(createText(text.slice(i, index), true));
|
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) {
|
if (icon && src) {
|
||||||
const img = new Image();
|
const img = new Image();
|
||||||
img.setAttribute("draggable", "false");
|
img.setAttribute("draggable", "false");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user