fix: The width of the sidebar changes abruptly by dragging it multiple times over and over again (bouncing)

This commit is contained in:
yhua1998 2023-09-13 16:55:31 +08:00
parent 28103c901d
commit 48e6087b1b

View File

@ -67,7 +67,13 @@ function useDragSideBar() {
lastUpdateTime.current = Date.now(); lastUpdateTime.current = Date.now();
const d = e.clientX - startX.current; const d = e.clientX - startX.current;
const nextWidth = limit(startDragWidth.current + d); const nextWidth = limit(startDragWidth.current + d);
config.update((config) => (config.sidebarWidth = nextWidth)); config.update((config) => {
if (nextWidth < MIN_SIDEBAR_WIDTH) {
config.sidebarWidth = NARROW_SIDEBAR_WIDTH;
} else {
config.sidebarWidth = nextWidth;
}
});
}); });
const handleMouseUp = useRef(() => { const handleMouseUp = useRef(() => {
@ -80,7 +86,7 @@ function useDragSideBar() {
const onDragMouseDown = (e: MouseEvent) => { const onDragMouseDown = (e: MouseEvent) => {
startX.current = e.clientX; startX.current = e.clientX;
// Remembers the initial width each time the mouse is pressed // Remembers the initial width each time the mouse is pressed
startDragWidth.current = config.sidebarWidth startDragWidth.current = config.sidebarWidth;
window.addEventListener("mousemove", handleMouseMove.current); window.addEventListener("mousemove", handleMouseMove.current);
window.addEventListener("mouseup", handleMouseUp.current); window.addEventListener("mouseup", handleMouseUp.current);
}; };