Skip to content

Commit

Permalink
Fix empty Patterns inserter when selecting section root when editing …
Browse files Browse the repository at this point in the history
…Pages in Site Editor (#66214)

* If selected block is the root then set as destination

* Set correct destination index

* Scope to Zoom Out only for 6.7
  • Loading branch information
getdave authored Oct 21, 2024
1 parent 0e34773 commit 1899810
Showing 1 changed file with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ function useInsertionPoint( {
getBlockRootClientId,
getBlockIndex,
getBlockOrder,
} = select( blockEditorStore );
getSectionRootClientId,
__unstableGetEditorMode,
} = unlock( select( blockEditorStore ) );
const selectedBlockClientId = getSelectedBlockClientId();

let _destinationRootClientId = rootClientId;
Expand All @@ -92,10 +94,26 @@ function useInsertionPoint( {
// Insert after a specific client ID.
_destinationIndex = getBlockIndex( clientId );
} else if ( ! isAppender && selectedBlockClientId ) {
_destinationRootClientId = getBlockRootClientId(
selectedBlockClientId
);
_destinationIndex = getBlockIndex( selectedBlockClientId ) + 1;
const sectionRootClientId = getSectionRootClientId();

// Avoids empty inserter when the selected block is acting
// as the "root".
// See https://github.com/WordPress/gutenberg/pull/66214.
if (
__unstableGetEditorMode() === 'zoom-out' &&
sectionRootClientId === selectedBlockClientId
) {
_destinationRootClientId = sectionRootClientId;
_destinationIndex = getBlockOrder(
_destinationRootClientId
).length;
} else {
_destinationRootClientId = getBlockRootClientId(
selectedBlockClientId
);
_destinationIndex =
getBlockIndex( selectedBlockClientId ) + 1;
}
} else {
// Insert at the end of the list.
_destinationIndex = getBlockOrder(
Expand Down

0 comments on commit 1899810

Please sign in to comment.