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 {