Skip to content

Commit

Permalink
Fix post content in site editor too
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed May 22, 2024
1 parent 627c696 commit 3f2127a
Showing 1 changed file with 35 additions and 18 deletions.
53 changes: 35 additions & 18 deletions packages/block-editor/src/components/block-list/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,28 @@ const applyWithDispatch = withDispatch( ( dispatch, ownProps, registry ) => {
canInsertBlockType,
} = registry.select( blockEditorStore );

function switchToDefaultOrRemove() {
const block = getBlock( clientId );
const defaultBlockName = getDefaultBlockName();
if ( getBlockName( clientId ) !== defaultBlockName ) {
const replacement = switchToBlockType(
block,
defaultBlockName
);
if ( replacement && replacement.length ) {
replaceBlocks( clientId, replacement );
}
} else if ( isUnmodifiedDefaultBlock( block ) ) {
const nextBlockClientId = getNextBlockClientId( clientId );
if ( nextBlockClientId ) {
registry.batch( () => {
removeBlock( clientId );
selectBlock( nextBlockClientId );
} );
}
}
}

/**
* Moves the block with clientId up one level. If the block type
* cannot be inserted at the new location, it will be attempted to
Expand Down Expand Up @@ -345,14 +367,25 @@ const applyWithDispatch = withDispatch( ( dispatch, ownProps, registry ) => {
getDefaultBlockName()
);

if ( replacement && replacement.length ) {
if (
replacement &&
replacement.length &&
replacement.every( ( block ) =>
canInsertBlockType(
block.name,
targetRootClientId
)
)
) {
insertBlocks(
replacement,
getBlockIndex( _clientId ),
targetRootClientId,
changeSelection
);
removeBlock( firstClientId, false );
} else {
switchToDefaultOrRemove();
}
}

Expand Down Expand Up @@ -463,24 +496,8 @@ const applyWithDispatch = withDispatch( ( dispatch, ownProps, registry ) => {
}

moveFirstItemUp( rootClientId );
} else if (
getBlockName( clientId ) !== getDefaultBlockName()
) {
const replacement = switchToBlockType(
getBlock( clientId ),
getDefaultBlockName()
);
if ( replacement && replacement.length ) {
replaceBlocks( clientId, replacement );
}
} else {
const nextBlockClientId = getNextBlockClientId( clientId );
if ( nextBlockClientId ) {
registry.batch( () => {
removeBlock( clientId );
selectBlock( nextBlockClientId );
} );
}
switchToDefaultOrRemove();
}
}
},
Expand Down

0 comments on commit 3f2127a

Please sign in to comment.