mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-24 10:40:07 +08:00
fix(SelectionAssistant): improve auto-scroll behavior in action window (#6999)
fix(SelectionActionApp): improve auto-scroll behavior and manage scroll height tracking
This commit is contained in:
parent
cd8c5115df
commit
26d018b1b7
@ -29,9 +29,10 @@ const SelectionActionApp: FC = () => {
|
||||
const [showOpacitySlider, setShowOpacitySlider] = useState(false)
|
||||
const [opacity, setOpacity] = useState(actionWindowOpacity)
|
||||
|
||||
const shouldCloseWhenBlur = useRef(false)
|
||||
const contentElementRef = useRef<HTMLDivElement>(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 {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user