From 055f881d2a95b93573587c59e3eeb646e6551600 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Fri, 31 Jan 2025 11:22:49 +0400 Subject: [PATCH] Block Editor: Display root appender when default block is disabled (#68951) * Block Editor: Display root appender when default block is disabled * Handle multi-selection Unlinked contributors: virgiliud, MGabrane, alexis-magina, sweco-seerjf. Co-authored-by: Mamaduka Co-authored-by: t-hamano --- .../src/components/block-list/index.js | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/packages/block-editor/src/components/block-list/index.js b/packages/block-editor/src/components/block-list/index.js index bcf6783a10d1c3..d3a2f0ae0795c8 100644 --- a/packages/block-editor/src/components/block-list/index.js +++ b/packages/block-editor/src/components/block-list/index.js @@ -19,6 +19,7 @@ import { useCallback, useEffect, } from '@wordpress/element'; +import { getDefaultBlockName } from '@wordpress/blocks'; /** * Internal dependencies @@ -171,13 +172,13 @@ function Items( { const { getSettings, getBlockOrder, - getSelectedBlockClientId, getSelectedBlockClientIds, __unstableGetVisibleBlocks, getTemplateLock, getBlockEditingMode, isSectionBlock, isZoomOut: _isZoomOut, + canInsertBlockType, } = unlock( select( blockEditorStore ) ); const _order = getBlockOrder( rootClientId ); @@ -190,10 +191,20 @@ function Items( { }; } - const selectedBlockClientId = getSelectedBlockClientId(); + const selectedBlockClientIds = getSelectedBlockClientIds(); + const selectedBlockClientId = selectedBlockClientIds[ 0 ]; + const showRootAppender = + ! rootClientId && + ! selectedBlockClientId && + ( ! _order.length || + ! canInsertBlockType( + getDefaultBlockName(), + rootClientId + ) ); + return { order: _order, - selectedBlocks: getSelectedBlockClientIds(), + selectedBlocks: selectedBlockClientIds, visibleBlocks: __unstableGetVisibleBlocks(), isZoomOut: _isZoomOut(), shouldRenderAppender: @@ -203,10 +214,8 @@ function Items( { hasAppender && ! _isZoomOut() && ( hasCustomAppender || - rootClientId === selectedBlockClientId || - ( ! rootClientId && - ! selectedBlockClientId && - ! _order.length ) ), + showRootAppender || + rootClientId === selectedBlockClientId ), }; }, [ rootClientId, hasAppender, hasCustomAppender ]