Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add fallback to selected block position
  • Loading branch information
ellatrix committed Apr 23, 2021
commit b4817ab4bab29804e0041be77d17c9fe7e4f8502
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,14 @@ function useInsertionPoint( {
const { destinationRootClientId, destinationIndex } = useSelect(
( select ) => {
const {
getSelectedBlockClientId,
getBlockRootClientId,
getBlockIndex,
getBlockOrder,
} = select( blockEditorStore );
const selectedBlockClientId = getSelectedBlockClientId();

const _destinationRootClientId = rootClientId;
let _destinationRootClientId = rootClientId;
let _destinationIndex;

if ( insertionIndex ) {
Expand All @@ -65,6 +68,15 @@ function useInsertionPoint( {
clientId,
_destinationRootClientId
);
} else if ( ! isAppender && selectedBlockClientId ) {
_destinationRootClientId = getBlockRootClientId(
selectedBlockClientId
);
_destinationIndex =
getBlockIndex(
selectedBlockClientId,
_destinationRootClientId
) + 1;
} else {
// Insert at the end of the list.
_destinationIndex = getBlockOrder( _destinationRootClientId )
Expand Down