From 775426ffe0a3b678c95f80dedaa000efb47583af Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 10 Sep 2026 08:44:16 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Optimize=20mouse=20event=20handler?= =?UTF-8?q?=20by=20removing=20querySelectorAll?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Horizontal42 <75383519+Horizontal42@users.noreply.github.com> --- src/main.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main.ts b/src/main.ts index cd60dde..423cce9 100644 --- a/src/main.ts +++ b/src/main.ts @@ -197,14 +197,23 @@ function setupDocInteraction(el: HTMLElement, doc: DocMeta, list: HTMLElement): window.removeEventListener("mousemove", onMove); window.removeEventListener("mouseup", onUp); list.removeEventListener("scroll", onScroll); - cachedItems = null; if (dragging) { - const target = list.querySelector(".doc-item.drag-over"); - for (const item of list.querySelectorAll(".doc-item")) - item.classList.remove("drag-over", "dragging"); + let target: HTMLElement | null = null; + if (cachedItems) { + for (let i = 0, len = cachedItems.length; i < len; i++) { + const item = cachedItems[i].el; + if (item.classList.contains("drag-over")) target = item; + item.classList.remove("drag-over", "dragging"); + } + } else { + target = list.querySelector(".doc-item.drag-over"); + for (const item of list.querySelectorAll(".doc-item")) + item.classList.remove("drag-over", "dragging"); + } document.body.style.cursor = ""; if (target?.dataset.docId) reorderDoc(doc.id, target.dataset.docId); } + cachedItems = null; dragging = false; }; window.addEventListener("mousemove", onMove);