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

Transform: select all blocks if the result has more than one block #45015

Merged
merged 6 commits into from
Nov 3, 2022
Merged
Changes from 1 commit
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
Next Next commit
Transform: select all blocks if the result has more than one block
ellatrix committed Nov 2, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 8e5705c472d3e0184d4327411b3bff894faac24d
19 changes: 15 additions & 4 deletions packages/block-editor/src/components/block-switcher/index.js
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ import PatternTransformationsMenu from './pattern-transformations-menu';
import useBlockDisplayTitle from '../block-title/use-block-display-title';

export const BlockSwitcherDropdownMenu = ( { clientIds, blocks } ) => {
const { replaceBlocks } = useDispatch( blockEditorStore );
const { replaceBlocks, multiSelect } = useDispatch( blockEditorStore );
const blockInformation = useBlockDisplayInformation( blocks[ 0 ].clientId );
const {
possibleBlockTransformations,
@@ -90,11 +90,22 @@ export const BlockSwitcherDropdownMenu = ( { clientIds, blocks } ) => {
const isTemplate = blocks.length === 1 && isTemplatePart( blocks[ 0 ] );

// Simple block tranformation based on the `Block Transforms` API.
const onBlockTransform = ( name ) =>
replaceBlocks( clientIds, switchToBlockType( blocks, name ) );
function onBlockTransform( name ) {
const newBlocks = switchToBlockType( blocks, name );
replaceBlocks( clientIds, newBlocks );
multiSelect(
ntsekouras marked this conversation as resolved.
Show resolved Hide resolved
newBlocks[ 0 ].clientId,
newBlocks[ newBlocks.length - 1 ].clientId
);
}
// Pattern transformation through the `Patterns` API.
const onPatternTransform = ( transformedBlocks ) =>
function onPatternTransform( transformedBlocks ) {
replaceBlocks( clientIds, transformedBlocks );
multiSelect(
ntsekouras marked this conversation as resolved.
Show resolved Hide resolved
transformedBlocks[ 0 ].clientId,
transformedBlocks[ transformedBlocks.length - 1 ].clientId
);
}

/**
* The `isTemplate` check is a stopgap solution here.