Skip to content

Commit

Permalink
[mini] drag and drop: restore moving animation (#67417)
Browse files Browse the repository at this point in the history
Co-authored-by: ellatrix <[email protected]>
Co-authored-by: youknowriad <[email protected]>
  • Loading branch information
3 people authored Nov 29, 2024
1 parent 96647ef commit 52b5429
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions packages/block-editor/src/components/use-moving-animation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,14 @@ function useMovingAnimation( { triggerAnimationOnChange, clientId } ) {
const isSelected = isBlockSelected( clientId );
const adjustScrolling =
isSelected || isFirstMultiSelectedBlock( clientId );
const isDragging = isDraggingBlocks();

function preserveScrollPosition() {
// The user already scrolled when dragging blocks.
if ( isDragging ) {
return;
}

if ( adjustScrolling && prevRect ) {
const blockRect = ref.current.getBoundingClientRect();
const diff = blockRect.top - prevRect.top;
Expand All @@ -86,11 +92,6 @@ function useMovingAnimation( { triggerAnimationOnChange, clientId } ) {
}
}

// Neither animate nor scroll.
if ( isDraggingBlocks() ) {
return;
}

// We disable the animation if the user has a preference for reduced
// motion, if the user is typing (insertion by Enter), or if the block
// count exceeds the threshold (insertion caused all the blocks that
Expand All @@ -113,6 +114,13 @@ function useMovingAnimation( { triggerAnimationOnChange, clientId } ) {
isSelected ||
isBlockMultiSelected( clientId ) ||
isAncestorMultiSelected( clientId );

// The user already dragged the blocks to the new position, so don't
// animate the dragged blocks.
if ( isPartOfSelection && isDragging ) {
return;
}

// Make sure the other blocks move under the selected block(s).
const zIndex = isPartOfSelection ? '1' : '';

Expand Down

0 comments on commit 52b5429

Please sign in to comment.