Skip to content

Commit 814c60a

Browse files
Compare block id instead of name
1 parent c926d69 commit 814c60a

File tree

1 file changed

+16
-7
lines changed
  • packages/block-editor/src/autocompleters

1 file changed

+16
-7
lines changed

packages/block-editor/src/autocompleters/block.js

+16-7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
createBlock,
77
createBlocksFromInnerBlocksTemplate,
88
parse,
9+
store as blocksStore,
910
} from '@wordpress/blocks';
1011
import { useMemo } from '@wordpress/element';
1112

@@ -36,22 +37,30 @@ function createBlockCompleter() {
3637
triggerPrefix: '/',
3738

3839
useItems( filterValue ) {
39-
const { rootClientId, selectedBlockName, prioritizedBlocks } =
40+
const { rootClientId, selectedBlockId, prioritizedBlocks } =
4041
useSelect( ( select ) => {
4142
const {
4243
getSelectedBlockClientId,
43-
getBlockName,
44+
getBlock,
4445
getBlockListSettings,
4546
getBlockRootClientId,
4647
} = select( blockEditorStore );
48+
const { getActiveBlockVariation } = select( blocksStore );
4749
const selectedBlockClientId = getSelectedBlockClientId();
50+
const { name: blockName, attributes } = getBlock(
51+
selectedBlockClientId
52+
);
53+
const activeBlockVariation = getActiveBlockVariation(
54+
blockName,
55+
attributes
56+
);
4857
const _rootClientId = getBlockRootClientId(
4958
selectedBlockClientId
5059
);
5160
return {
52-
selectedBlockName: selectedBlockClientId
53-
? getBlockName( selectedBlockClientId )
54-
: null,
61+
selectedBlockId: activeBlockVariation
62+
? `${ blockName }/${ activeBlockVariation.name }`
63+
: blockName,
5564
rootClientId: _rootClientId,
5665
prioritizedBlocks:
5766
getBlockListSettings( _rootClientId )
@@ -78,11 +87,11 @@ function createBlockCompleter() {
7887
);
7988

8089
return initialFilteredItems
81-
.filter( ( item ) => item.name !== selectedBlockName )
90+
.filter( ( item ) => item.id !== selectedBlockId )
8291
.slice( 0, SHOWN_BLOCK_TYPES );
8392
}, [
8493
filterValue,
85-
selectedBlockName,
94+
selectedBlockId,
8695
items,
8796
categories,
8897
collections,

0 commit comments

Comments
 (0)