Skip to content

Commit

Permalink
Insert in correct location for root insertions
Browse files Browse the repository at this point in the history
  • Loading branch information
jeryj committed Sep 10, 2024
1 parent efa5ffe commit a90bb7f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,21 @@ function useInsertionPoint( {
getInserterInsertionPoint,
} = unlock( select( blockEditorStore ) );
const selectedBlockClientId = getSelectedBlockClientId();

let _destinationRootClientId = rootClientId;
let _destinationIndex;
const insertionPoint = getInserterInsertionPoint();

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -83,7 +83,7 @@ export default function QuickInserter( {
}
}, [ setInserterIsOpened ] );

const { showInsertionPoint, setInserterInsertionPoint } = unlock(
const { setInserterInsertionPoint } = unlock(
useDispatch( blockEditorStore )
);

Expand All @@ -95,7 +95,6 @@ export default function QuickInserter( {
onSelect,
} );
setInserterInsertionPoint( { rootClientId, insertionIndex } );
showInsertionPoint( rootClientId, insertionIndex );
};

let maxBlockPatterns = 0;
Expand Down

0 comments on commit a90bb7f

Please sign in to comment.