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

Hide separators for currently dragged section in Zoom Out #67638

Merged
merged 2 commits into from
Dec 11, 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 @@ -33,13 +33,15 @@ export function ZoomOutSeparator( {
insertionPoint,
blockInsertionPointVisible,
blockInsertionPoint,
blocksBeingDragged,
} = useSelect( ( select ) => {
const {
getInsertionPoint,
getBlockOrder,
getSectionRootClientId,
isBlockInsertionPointVisible,
getBlockInsertionPoint,
getDraggedBlockClientIds,
} = unlock( select( blockEditorStore ) );

const root = getSectionRootClientId();
Expand All @@ -51,6 +53,7 @@ export function ZoomOutSeparator( {
insertionPoint: getInsertionPoint(),
blockInsertionPoint: getBlockInsertionPoint(),
blockInsertionPointVisible: isBlockInsertionPointVisible(),
blocksBeingDragged: getDraggedBlockClientIds(),
};
}, [] );

Expand Down Expand Up @@ -78,6 +81,7 @@ export function ZoomOutSeparator( {
insertionPoint &&
insertionPoint.hasOwnProperty( 'index' ) &&
clientId === sectionClientIds[ insertionPoint.index - 1 ];

// We want to show the zoom out separator in either of these conditions:
// 1. If the inserter has an insertion index set
// 2. We are dragging a pattern over an insertion point
Expand All @@ -97,6 +101,32 @@ export function ZoomOutSeparator( {
sectionClientIds[ blockInsertionPoint.index - 1 ] );
}

const blockBeingDraggedClientId = blocksBeingDragged[ 0 ];

const isCurrentBlockBeingDragged = blocksBeingDragged.includes( clientId );

const blockBeingDraggedIndex = sectionClientIds.indexOf(
blockBeingDraggedClientId
);
const blockBeingDraggedPreviousSiblingClientId =
blockBeingDraggedIndex > 0
? sectionClientIds[ blockBeingDraggedIndex - 1 ]
: null;

const isCurrentBlockPreviousSiblingOfBlockBeingDragged =
blockBeingDraggedPreviousSiblingClientId === clientId;

// The separators are visually top/bottom of the block, but in actual fact
// the "top" separator is the "bottom" separator of the previous block.
// Therefore, this logic hides the separator if the current block is being dragged
// or if the current block is the previous sibling of the block being dragged.
if (
isCurrentBlockBeingDragged ||
isCurrentBlockPreviousSiblingOfBlockBeingDragged
) {
isVisible = false;
}

return (
<AnimatePresence>
{ isVisible && (
Expand Down
Loading