From cdb57ebda031e805738f84d6a4b3dae99c40526a Mon Sep 17 00:00:00 2001 From: djmaze Date: Sat, 18 Feb 2023 10:46:08 +0100 Subject: [PATCH] Don't use live NodeList --- source/node/MergeSplit.ts | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/source/node/MergeSplit.ts b/source/node/MergeSplit.ts index c819bf9..abd6158 100644 --- a/source/node/MergeSplit.ts +++ b/source/node/MergeSplit.ts @@ -59,18 +59,14 @@ const fixContainer = ( container: Node, root: Element | DocumentFragment, ): Node => { - const children = container.childNodes; let wrapper: HTMLElement | null = null; - for (let i = 0, l = children.length; i < l; i += 1) { - const child = children[i]; + [...container.childNodes].forEach(child => { const isBR = child.nodeName === 'BR'; if (!isBR && isInline(child)) { if (!wrapper) { wrapper = createElement('DIV'); } wrapper.appendChild(child); - i -= 1; - l -= 1; } else if (isBR || wrapper) { if (!wrapper) { wrapper = createElement('DIV'); @@ -80,15 +76,13 @@ const fixContainer = ( container.replaceChild(wrapper, child); } else { container.insertBefore(wrapper, child); - i += 1; - l += 1; } wrapper = null; } if (isContainer(child)) { fixContainer(child, root); } - } + }); if (wrapper) { container.appendChild(fixCursor(wrapper)); }