fix(grid): smooth canvas horizontal scroll

This commit is contained in:
t8y2 2026-06-26 02:26:26 +08:00
parent 54e0393ab3
commit c1280511ae
1 changed files with 18 additions and 7 deletions

View File

@ -4195,20 +4195,31 @@ function onCanvasScroll(event: Event) {
const scrollLeft = scroller.scrollLeft;
const viewportWidth = scroller.clientWidth;
const viewportHeight = scroller.clientHeight;
const scrollTopChanged = canvasScrollTop.value !== scrollTop;
const viewportHeightChanged = canvasViewportHeight.value !== viewportHeight;
const scrollLeftChanged = gridHorizontalScrollLeft.value !== scrollLeft;
const viewportWidthChanged = gridViewportWidth.value !== viewportWidth || canvasViewportWidth.value !== viewportWidth;
if (canvasScrollTop.value !== scrollTop) canvasScrollTop.value = scrollTop;
if (canvasViewportWidth.value !== viewportWidth) canvasViewportWidth.value = viewportWidth;
if (canvasViewportHeight.value !== viewportHeight) canvasViewportHeight.value = viewportHeight;
if (gridHorizontalScrollLeft.value !== scrollLeft || gridViewportWidth.value !== viewportWidth) {
updateGridHorizontalViewport(scroller);
if (scrollLeftChanged || viewportWidthChanged) {
gridHorizontalScrollLeft.value = scrollLeft;
gridViewportWidth.value = viewportWidth;
updateGridHorizontalScrollbar(scroller);
}
if (scrollTopChanged || viewportHeightChanged) {
updateGridVerticalScrollbar(scroller);
maybeCheckInfiniteScroll(scroller);
}
if (viewportWidthChanged || viewportHeightChanged) {
const gutter = scrollbarGutterWidth(scroller);
if (gridScrollbarGutter.value !== gutter) gridScrollbarGutter.value = gutter;
}
updateGridVerticalScrollbar(scroller);
const gutter = scrollbarGutterWidth(scroller);
if (gridScrollbarGutter.value !== gutter) gridScrollbarGutter.value = gutter;
if (headerRef.value && headerRef.value.scrollLeft !== scrollLeft) headerRef.value.scrollLeft = scrollLeft;
recordScrollPosition({ top: scrollTop, left: scrollLeft });
markGridScrolling();
scheduleCanvasDraw();
maybeCheckInfiniteScroll(scroller);
}
function canvasWheelDeltaToPixels(delta: number, deltaMode: number, pageSize: number): number {
@ -4220,7 +4231,7 @@ function canvasWheelDeltaToPixels(delta: number, deltaMode: number, pageSize: nu
function shouldAccelerateCanvasWheel(event: WheelEvent): boolean {
if (event.ctrlKey || event.metaKey) return false;
if (event.deltaMode !== WheelEvent.DOM_DELTA_PIXEL) return true;
return Math.abs(event.deltaY) >= CANVAS_TRACKPAD_DELTA_THRESHOLD || Math.abs(event.deltaX) >= CANVAS_TRACKPAD_DELTA_THRESHOLD;
return event.shiftKey && Math.abs(event.deltaY) > Math.abs(event.deltaX) && Math.abs(event.deltaY) >= CANVAS_TRACKPAD_DELTA_THRESHOLD;
}
function onCanvasWheel(event: WheelEvent) {