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

Avoid unnecessary heading level and paragraph transform via keyboard shortcuts #60955

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
Loading