Skip to content

Commit

Permalink
Hide separators for currently dragged section in Zoom Out (WordPress#…
Browse files Browse the repository at this point in the history
…67638)

* Hide separators for currently dragged section

* Add comment by way of explanation

Co-authored-by: getdave <[email protected]>
Co-authored-by: richtabor <[email protected]>
Co-authored-by: mikachan <[email protected]>
  • Loading branch information
4 people authored and yogeshbhutkar committed Dec 18, 2024
1 parent 2f3f4a0 commit 6ce7ec6
Showing 1 changed file with 30 additions and 0 deletions.
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

0 comments on commit 6ce7ec6

Please sign in to comment.