Skip to content
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
23 changes: 20 additions & 3 deletions packages/block-library/src/block-keyboard-shortcuts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,34 @@ function BlockKeyboardShortcuts() {

const handleTransformHeadingAndParagraph = ( event, level ) => {
event.preventDefault();
const destinationBlockName =
level === 0 ? 'core/paragraph' : 'core/heading';

const currentClientId = getSelectedBlockClientId();
if ( currentClientId === null ) {
return;
}

const blockName = getBlockName( currentClientId );
if ( blockName !== 'core/paragraph' && blockName !== 'core/heading' ) {
const isParagraph = blockName === 'core/paragraph';
const isHeading = blockName === 'core/heading';

if ( ! isParagraph && ! isHeading ) {
return;
}

const destinationBlockName =
level === 0 ? 'core/paragraph' : 'core/heading';

const attributes = getBlockAttributes( currentClientId );

// Avoid unnecessary block transform when attempting to transform to
// the same block type and/or same level.
if (
( isParagraph && level === 0 ) ||
( isHeading && attributes.level === level )
) {
return;
}

const textAlign =
blockName === 'core/paragraph' ? 'align' : 'textAlign';
const destinationTextAlign =
Expand Down