Skip to content

Commit

Permalink
Show paragraph block variations in rich text inserter (#66318)
Browse files Browse the repository at this point in the history
Co-authored-by: SantosGuillamot <santosguillamot@git.wordpress.org>
Co-authored-by: gziolo <gziolo@git.wordpress.org>
  • Loading branch information
3 people authored Oct 28, 2024
1 parent 13be440 commit 6372ef7
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions packages/block-editor/src/autocompleters/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
createBlock,
createBlocksFromInnerBlocksTemplate,
parse,
store as blocksStore,
} from '@wordpress/blocks';
import { useMemo } from '@wordpress/element';

Expand Down Expand Up @@ -36,22 +37,30 @@ function createBlockCompleter() {
triggerPrefix: '/',

useItems( filterValue ) {
const { rootClientId, selectedBlockName, prioritizedBlocks } =
const { rootClientId, selectedBlockId, prioritizedBlocks } =
useSelect( ( select ) => {
const {
getSelectedBlockClientId,
getBlockName,
getBlock,
getBlockListSettings,
getBlockRootClientId,
} = select( blockEditorStore );
const { getActiveBlockVariation } = select( blocksStore );
const selectedBlockClientId = getSelectedBlockClientId();
const { name: blockName, attributes } = getBlock(
selectedBlockClientId
);
const activeBlockVariation = getActiveBlockVariation(
blockName,
attributes
);
const _rootClientId = getBlockRootClientId(
selectedBlockClientId
);
return {
selectedBlockName: selectedBlockClientId
? getBlockName( selectedBlockClientId )
: null,
selectedBlockId: activeBlockVariation
? `${ blockName }/${ activeBlockVariation.name }`
: blockName,
rootClientId: _rootClientId,
prioritizedBlocks:
getBlockListSettings( _rootClientId )
Expand All @@ -78,11 +87,11 @@ function createBlockCompleter() {
);

return initialFilteredItems
.filter( ( item ) => item.name !== selectedBlockName )
.filter( ( item ) => item.id !== selectedBlockId )
.slice( 0, SHOWN_BLOCK_TYPES );
}, [
filterValue,
selectedBlockName,
selectedBlockId,
items,
categories,
collections,
Expand Down

0 comments on commit 6372ef7

Please sign in to comment.