Skip to content

Commit

Permalink
Hide separators for currently dragged section
Browse files Browse the repository at this point in the history
  • Loading branch information
getdave committed Dec 6, 2024
1 parent 0d7312b commit b8b76b7
Showing 1 changed file with 26 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,28 @@ 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;

if (
isCurrentBlockBeingDragged ||
isCurrentBlockPreviousSiblingOfBlockBeingDragged
) {
isVisible = false;
}

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

0 comments on commit b8b76b7

Please sign in to comment.