diff --git a/src/components/proxy/proxy-groups.tsx b/src/components/proxy/proxy-groups.tsx index eeb65993..57fdec40 100644 --- a/src/components/proxy/proxy-groups.tsx +++ b/src/components/proxy/proxy-groups.tsx @@ -115,6 +115,7 @@ const LetterItem = memo( top: 0, right: 0, }); + const hoverTimeoutRef = useRef>(); const updateTooltipPosition = useCallback(() => { if (!letterRef.current) return; @@ -131,14 +132,37 @@ const LetterItem = memo( } }, [showTooltip, updateTooltipPosition]); + const handleMouseEnter = useCallback(() => { + setShowTooltip(true); + // 添加 200ms 的延迟,避免鼠标快速划过时触发滚动 + hoverTimeoutRef.current = setTimeout(() => { + onClick(name); + }, 100); + }, [name, onClick]); + + const handleMouseLeave = useCallback(() => { + setShowTooltip(false); + if (hoverTimeoutRef.current) { + clearTimeout(hoverTimeoutRef.current); + } + }, []); + + useEffect(() => { + return () => { + if (hoverTimeoutRef.current) { + clearTimeout(hoverTimeoutRef.current); + } + }; + }, []); + return ( <>
onClick(name)} - onMouseEnter={() => setShowTooltip(true)} - onMouseLeave={() => setShowTooltip(false)} + onMouseEnter={handleMouseEnter} + onMouseLeave={handleMouseLeave} > {getFirstChar(name)}