Skip to content

Commit

Permalink
fix(indexes): 调整长按滑动侧边栏时的取值方法
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyan-u committed Sep 6, 2024
1 parent b96a048 commit 0bc5efe
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/indexes/Indexes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ const Indexes: React.FC<IndexesProps> = (props) => {
const childNodes = useRef<ChildNodes[]>([]);
const parentRect = useRef({ top: 0 });

const touchActiveIndex = useRef<string>('');

const indexListMemo = useMemo(() => {
if (!indexList) {
const start = 'A'.charCodeAt(0);
Expand Down Expand Up @@ -152,14 +150,10 @@ const Indexes: React.FC<IndexesProps> = (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);
}
}
};
Expand Down

0 comments on commit 0bc5efe

Please sign in to comment.