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

Fix empty Patterns inserter when selecting section root when editing Pages in Site Editor #66214

Merged
merged 3 commits into from
Oct 21, 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 @@ -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 ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just adding __unstableGetEditorMode() !== 'zoom-out' to this conditional is enough to get the right things you want. You don't need to set the _destinationRootClientId = sectionRootClientId; later on, as it should be the same or not matter.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this PR would just become

Suggested change
} else if ( ! isAppender && selectedBlockClientId ) {
} else if ( ! isAppender && selectedBlockClientId && __unstableGetEditorMode() !== 'zoom-out') {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless I'm confused, I don't think we can do that.

This code block needs to run even if not in zoom out. It's only setting destination* variables that's different in zoom out.

_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
Loading