From 82b31f09dd3710d2181345e99d4e04cd4ed4bdec Mon Sep 17 00:00:00 2001 From: Andrew Serong <14988353+andrewserong@users.noreply.github.com> Date: Thu, 27 Apr 2023 15:06:55 +1000 Subject: [PATCH] List View: Fix scroll to top issue when dragging the second last block in the list --- .../block-draggable/use-scroll-when-dragging.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/block-editor/src/components/block-draggable/use-scroll-when-dragging.js b/packages/block-editor/src/components/block-draggable/use-scroll-when-dragging.js index aa66c27503cf9..a01db4927b652 100644 --- a/packages/block-editor/src/components/block-draggable/use-scroll-when-dragging.js +++ b/packages/block-editor/src/components/block-draggable/use-scroll-when-dragging.js @@ -78,7 +78,10 @@ export default function useScrollWhenDragging() { SCROLL_INACTIVE_DISTANCE_PX, 0 ); - const distancePercentage = dragDistance / moveableDistance; + const distancePercentage = + moveableDistance === 0 || dragDistance === 0 + ? 0 + : dragDistance / moveableDistance; velocityY.current = VELOCITY_MULTIPLIER * distancePercentage; } else if ( event.clientY < offsetDragStartPosition ) { // User is dragging upwards. @@ -92,7 +95,10 @@ export default function useScrollWhenDragging() { SCROLL_INACTIVE_DISTANCE_PX, 0 ); - const distancePercentage = dragDistance / moveableDistance; + const distancePercentage = + moveableDistance === 0 || dragDistance === 0 + ? 0 + : dragDistance / moveableDistance; velocityY.current = -VELOCITY_MULTIPLIER * distancePercentage; } else { velocityY.current = 0;