feat: add auto-scroll during drag near sidebar edges
This commit is contained in:
@@ -178,8 +178,44 @@ export function useDragManager(opts: UseDragManagerOpts) {
|
|||||||
voiceHoverChannelId, activeDrag,
|
voiceHoverChannelId, activeDrag,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Suppress unused variable warnings for incremental build
|
// --- Auto-scroll during drag (fixes bug 7) ---
|
||||||
void scrollContainerRef;
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!activeDrag || !scrollContainerRef.current) return;
|
||||||
|
const container = scrollContainerRef.current;
|
||||||
|
const EDGE_PX = 40;
|
||||||
|
let scrollSpeed = 0;
|
||||||
|
let rafId = 0;
|
||||||
|
|
||||||
|
const onDragOver = (e: DragEvent) => {
|
||||||
|
const rect = container.getBoundingClientRect();
|
||||||
|
const distFromTop = e.clientY - rect.top;
|
||||||
|
const distFromBottom = rect.bottom - e.clientY;
|
||||||
|
|
||||||
|
if (distFromTop < EDGE_PX) {
|
||||||
|
scrollSpeed = -(1 + 7 * (1 - distFromTop / EDGE_PX));
|
||||||
|
} else if (distFromBottom < EDGE_PX) {
|
||||||
|
scrollSpeed = 1 + 7 * (1 - distFromBottom / EDGE_PX);
|
||||||
|
} else {
|
||||||
|
scrollSpeed = 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const tick = () => {
|
||||||
|
if (scrollSpeed !== 0) {
|
||||||
|
container.scrollTop += scrollSpeed;
|
||||||
|
}
|
||||||
|
rafId = requestAnimationFrame(tick);
|
||||||
|
};
|
||||||
|
|
||||||
|
container.addEventListener('dragover', onDragOver);
|
||||||
|
rafId = requestAnimationFrame(tick);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
container.removeEventListener('dragover', onDragOver);
|
||||||
|
cancelAnimationFrame(rafId);
|
||||||
|
};
|
||||||
|
}, [activeDrag, scrollContainerRef]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
activeDrag,
|
activeDrag,
|
||||||
|
|||||||
Reference in New Issue
Block a user