From c3e65767a59ebb4ea7215159bf48efb134c83f78 Mon Sep 17 00:00:00 2001 From: Carlos Garcia Date: Fri, 6 May 2022 17:06:51 +0200 Subject: [PATCH] Update dragging enabled calculation In order to prevent issues related to disabling the long-press gesture in elements within the block UI, the logic for enabling the dragging has been updated. Now it will enabled in the following cases: - The block doesn't have inner blocks. This applies to root blocks and nested blocks without further nested blocks. - Blocks with nested blocks if the block is selected. - Blocks with nested blocks if none of the nested blocks is selected. --- .../src/components/block-list/block.native.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/block-editor/src/components/block-list/block.native.js b/packages/block-editor/src/components/block-list/block.native.js index 11cc5f1e31f6b9..822194e749906d 100644 --- a/packages/block-editor/src/components/block-list/block.native.js +++ b/packages/block-editor/src/components/block-list/block.native.js @@ -260,8 +260,9 @@ class BlockListBlock extends Component { /> ) } { () => isValid ? ( @@ -319,6 +320,7 @@ export default compose( [ withSelect( ( select, { clientId } ) => { const { getBlockIndex, + getBlockCount, getSettings, isBlockSelected, getBlock, @@ -371,14 +373,17 @@ export default compose( [ const baseGlobalStyles = getSettings() ?.__experimentalGlobalStylesBaseStyles; - const topRootClientId = getBlockHierarchyRootClientId( clientId ); - const isRootBlock = clientId === topRootClientId; - // For blocks with inner blocks, we only enable the dragging in the nested blocks. This way - // we prevent the long-press gesture from being disabled for elements within the block UI. - const draggingEnabled = ! isRootBlock || ! isInnerBlockSelected; + const hasInnerBlocks = getBlockCount( clientId ) > 0; + // For blocks with inner blocks, we only enable the dragging in the nested + // blocks if any of them are selected. This way we prevent the long-press + // gesture from being disabled for elements within the block UI. + const draggingEnabled = + ! hasInnerBlocks || + isSelected || + ! hasSelectedInnerBlock( clientId, true ); // Dragging nested blocks is not supported yet. For this reason, the block to be dragged // will be the top in the hierarchy. - const draggingClientId = topRootClientId; + const draggingClientId = getBlockHierarchyRootClientId( clientId ); return { icon,