diff --git a/packages/editor/src/store/selectors.js b/packages/editor/src/store/selectors.js index 619c0e381712a5..c80309bb131a27 100644 --- a/packages/editor/src/store/selectors.js +++ b/packages/editor/src/store/selectors.js @@ -729,7 +729,7 @@ export const getClientIdsWithDescendants = createSelector( export const getGlobalBlockCount = createSelector( ( state, blockName ) => { if ( ! blockName ) { - return size( state.editor.present.blocks.byClientId ); + return size( state.editor.present.blocks.byClientId ) - size( state.reusableBlocks.data ); } return reduce( state.editor.present.blocks.byClientId, diff --git a/packages/editor/src/store/test/selectors.js b/packages/editor/src/store/test/selectors.js index 1470f2261db39c..8e35c07ef6134e 100644 --- a/packages/editor/src/store/test/selectors.js +++ b/packages/editor/src/store/test/selectors.js @@ -2523,12 +2523,37 @@ describe( 'selectors', () => { }, }, }, + reusableBlocks: { + data: {}, + }, }; expect( getGlobalBlockCount( state ) ).toBe( 2 ); } ); - it( 'should return the global umber of blocks of a given type', () => { + it( 'should exclude blocks referenced by reusable blocks from the count', () => { + const state = { + editor: { + present: { + blocks: { + byClientId: { + 123: { clientId: 123, name: 'core/paragraph', attributes: {} }, + 456: { clientId: 456, name: 'core/paragraph', attributes: {} }, + }, + }, + }, + }, + reusableBlocks: { + data: { + 1: { clientId: 456 }, + }, + }, + }; + + expect( getGlobalBlockCount( state ) ).toBe( 1 ); + } ); + + it( 'should return the global number of blocks of a given type', () => { const state = { editor: { present: { @@ -2542,6 +2567,9 @@ describe( 'selectors', () => { }, }, }, + reusableBlocks: { + data: {}, + }, }; expect( getGlobalBlockCount( state, 'core/heading' ) ).toBe( 1 ); @@ -2556,6 +2584,9 @@ describe( 'selectors', () => { }, }, }, + reusableBlocks: { + data: {}, + }, }; expect( getGlobalBlockCount( state ) ).toBe( 0 ); expect( getGlobalBlockCount( state, 'core/heading' ) ).toBe( 0 );