From a90bb7f21b6c33fffb353e686ab621489f085c72 Mon Sep 17 00:00:00 2001 From: Jerry Jones Date: Tue, 10 Sep 2024 11:20:40 -0500 Subject: [PATCH] Insert in correct location for root insertions --- .../components/inserter/hooks/use-insertion-point.js | 12 +++++------- .../src/components/inserter/quick-inserter.js | 5 ++--- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/packages/block-editor/src/components/inserter/hooks/use-insertion-point.js b/packages/block-editor/src/components/inserter/hooks/use-insertion-point.js index 3d26707a6d5cae..e0defd2317bc66 100644 --- a/packages/block-editor/src/components/inserter/hooks/use-insertion-point.js +++ b/packages/block-editor/src/components/inserter/hooks/use-insertion-point.js @@ -82,7 +82,6 @@ function useInsertionPoint( { getInserterInsertionPoint, } = unlock( select( blockEditorStore ) ); const selectedBlockClientId = getSelectedBlockClientId(); - let _destinationRootClientId = rootClientId; let _destinationIndex; const insertionPoint = getInserterInsertionPoint(); @@ -90,15 +89,14 @@ function useInsertionPoint( { if ( insertionIndex !== undefined ) { // Insert into a specific index. _destinationIndex = insertionIndex; + } else if ( insertionPoint?.insertionIndex ) { + _destinationRootClientId = insertionPoint?.rootClientId + ? insertionPoint.rootClientId + : rootClientId; + _destinationIndex = insertionPoint.insertionIndex; } else if ( clientId ) { // Insert after a specific client ID. _destinationIndex = getBlockIndex( clientId ); - } else if ( - insertionPoint?.insertionIndex && - insertionPoint?.rootClientId - ) { - _destinationRootClientId = insertionPoint.rootClientId; - _destinationIndex = insertionPoint.insertionIndex; } else if ( ! isAppender && selectedBlockClientId ) { _destinationRootClientId = getBlockRootClientId( selectedBlockClientId diff --git a/packages/block-editor/src/components/inserter/quick-inserter.js b/packages/block-editor/src/components/inserter/quick-inserter.js index 2d3fa830ac9667..95d6956a51eace 100644 --- a/packages/block-editor/src/components/inserter/quick-inserter.js +++ b/packages/block-editor/src/components/inserter/quick-inserter.js @@ -9,7 +9,7 @@ import clsx from 'clsx'; import { useState, useEffect } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; import { Button, SearchControl } from '@wordpress/components'; -import { useSelect } from '@wordpress/data'; +import { useDispatch, useSelect } from '@wordpress/data'; /** * Internal dependencies @@ -83,7 +83,7 @@ export default function QuickInserter( { } }, [ setInserterIsOpened ] ); - const { showInsertionPoint, setInserterInsertionPoint } = unlock( + const { setInserterInsertionPoint } = unlock( useDispatch( blockEditorStore ) ); @@ -95,7 +95,6 @@ export default function QuickInserter( { onSelect, } ); setInserterInsertionPoint( { rootClientId, insertionIndex } ); - showInsertionPoint( rootClientId, insertionIndex ); }; let maxBlockPatterns = 0;