From 0bc5efea623797fab10a179bcfa537c70ace805c Mon Sep 17 00:00:00 2001 From: Lyan-u Date: Fri, 6 Sep 2024 03:42:34 +0000 Subject: [PATCH] =?UTF-8?q?fix(indexes):=20=E8=B0=83=E6=95=B4=E9=95=BF?= =?UTF-8?q?=E6=8C=89=E6=BB=91=E5=8A=A8=E4=BE=A7=E8=BE=B9=E6=A0=8F=E6=97=B6?= =?UTF-8?q?=E7=9A=84=E5=8F=96=E5=80=BC=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/indexes/Indexes.tsx | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/indexes/Indexes.tsx b/src/indexes/Indexes.tsx index f45f1e54..b634bc0f 100644 --- a/src/indexes/Indexes.tsx +++ b/src/indexes/Indexes.tsx @@ -49,8 +49,6 @@ const Indexes: React.FC = (props) => { const childNodes = useRef([]); const parentRect = useRef({ top: 0 }); - const touchActiveIndex = useRef(''); - const indexListMemo = useMemo(() => { if (!indexList) { const start = 'A'.charCodeAt(0); @@ -152,14 +150,10 @@ const Indexes: React.FC = (props) => { const target = document.elementFromPoint(clientX, clientY); if (target && target.className === `${name}__sidebar-item` && target instanceof HTMLElement) { const { index } = target.dataset; - // const curIndex = /^\d+$/.test(index ?? '') ? Number(index) : index; - if (index !== undefined && touchActiveIndex.current !== index) { - touchActiveIndex.current = index; - const curIndex = childNodes.current.find((child) => String(child.anchor) === index)?.anchor; - if (curIndex !== undefined) { - setActiveSidebarAndTip(curIndex); - scrollToByIndex(curIndex); - } + const curIndex = indexListMemo.find((idx) => String(idx) === index); + if (curIndex !== undefined && activeSidebar !== index) { + setActiveSidebarAndTip(curIndex); + scrollToByIndex(curIndex); } } };