Skip to content

Commit

Permalink
fix: auto scroll issue on the replay
Browse files Browse the repository at this point in the history
  • Loading branch information
wqcstrong committed Dec 24, 2024
1 parent 7eef3dd commit e127b47
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/pages/Replay/PluginPanel/components/ConsolePanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,24 @@ export const ConsolePanel = memo(() => {
});
}, [consoleMsg, autoScroll]);

const currentScrollTop = useRef<number>(0);
useEffect(() => {
const parent = panelRef.current?.parentElement;
if (!parent) return;

let scrollY = 0;
const fn = () => {
const value = parent.scrollTop;
if (value < scrollY) {
const handleScroll = () => {
const direction =
parent.scrollTop > currentScrollTop.current ? 'down' : 'up';
currentScrollTop.current = parent.scrollTop;

if (direction === 'up') {
setAutoScroll(false);
} else {
setAutoScroll(true);
return;
}
scrollY = value;
};
parent.addEventListener('scroll', fn);
parent.addEventListener('scroll', handleScroll);
return () => {
parent.removeEventListener('scroll', fn);
parent.removeEventListener('scroll', handleScroll);
};
}, [setAutoScroll]);

Expand Down

0 comments on commit e127b47

Please sign in to comment.