Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drag and drop: restore moving animation #67417

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading