Skip to content

Commit

Permalink
Avoid unnecessary heading level and paragraph transform via keyboard …
Browse files Browse the repository at this point in the history
…shortcuts. (#60955)

Co-authored-by: afercia <afercia@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
  • Loading branch information
3 people committed Apr 22, 2024
1 parent a6908f4 commit a4cf311
Showing 1 changed file with 20 additions and 3 deletions.
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

1 comment on commit a4cf311

@github-actions
Copy link

Choose a reason for hiding this comment

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

Flaky tests detected in a4cf311.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/8785697321
📝 Reported issues:

Please sign in to comment.