From 26d018b1b75c757a63c9d50ddf72a57a7cac8983 Mon Sep 17 00:00:00 2001 From: fullex <106392080+0xfullex@users.noreply.github.com> Date: Wed, 11 Jun 2025 13:03:52 +0800 Subject: [PATCH] fix(SelectionAssistant): improve auto-scroll behavior in action window (#6999) fix(SelectionActionApp): improve auto-scroll behavior and manage scroll height tracking --- .../selection/action/SelectionActionApp.tsx | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/renderer/src/windows/selection/action/SelectionActionApp.tsx b/src/renderer/src/windows/selection/action/SelectionActionApp.tsx index 3366c76b58..57c2b51902 100644 --- a/src/renderer/src/windows/selection/action/SelectionActionApp.tsx +++ b/src/renderer/src/windows/selection/action/SelectionActionApp.tsx @@ -29,9 +29,10 @@ const SelectionActionApp: FC = () => { const [showOpacitySlider, setShowOpacitySlider] = useState(false) const [opacity, setOpacity] = useState(actionWindowOpacity) + const shouldCloseWhenBlur = useRef(false) const contentElementRef = useRef(null) const isAutoScrollEnabled = useRef(true) - const shouldCloseWhenBlur = useRef(false) + const lastScrollHeight = useRef(0) useEffect(() => { if (isAutoPin) { @@ -80,6 +81,8 @@ const SelectionActionApp: FC = () => { const contentEl = contentElementRef.current if (contentEl) { contentEl.addEventListener('scroll', handleUserScroll) + // Initialize the scroll height + lastScrollHeight.current = contentEl.scrollHeight } return () => { if (contentEl) { @@ -140,6 +143,7 @@ const SelectionActionApp: FC = () => { setOpacity(value) } + //must useCallback to avoid re-rendering the component const handleScrollToBottom = useCallback(() => { if (contentElementRef.current && isAutoScrollEnabled.current) { contentElementRef.current.scrollTo({ @@ -153,9 +157,19 @@ const SelectionActionApp: FC = () => { if (!contentElementRef.current) return const { scrollTop, scrollHeight, clientHeight } = contentElementRef.current - const isAtBottom = Math.abs(scrollHeight - scrollTop - clientHeight) < 24 - // Only update isAutoScrollEnabled if user is at bottom + // Check if content height has increased (new content added) + const contentIncreased = scrollHeight > lastScrollHeight.current + lastScrollHeight.current = scrollHeight + + // If content increased and we're in auto-scroll mode, don't change the auto-scroll state + if (contentIncreased && isAutoScrollEnabled.current) { + return + } + + // Only check user position if content didn't increase + const isAtBottom = Math.abs(scrollHeight - scrollTop - clientHeight) < 32 + if (isAtBottom) { isAutoScrollEnabled.current = true } else {