Skip to content

Commit

Permalink
In-between inserter: preserve original behaviour (#31266)
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix authored Apr 28, 2021
1 parent 43b65a7 commit e54afb8
Showing 1 changed file with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { InsertionPointOpenRef } from './insertion-point';
export function useInBetweenInserter() {
const openRef = useContext( InsertionPointOpenRef );
const {
getBlockInsertionPoint,
getBlockListSettings,
getBlockRootClientId,
getBlockIndex,
Expand Down Expand Up @@ -68,7 +67,7 @@ export function useInBetweenInserter() {
const offsetLeft = event.clientX - rect.left;

const children = Array.from( event.target.children );
const nextElement = children.find( ( blockEl ) => {
let element = children.find( ( blockEl ) => {
return (
( blockEl.classList.contains( 'wp-block' ) &&
orientation === 'vertical' &&
Expand All @@ -79,8 +78,6 @@ export function useInBetweenInserter() {
);
} );

let element = nextElement || children[ children.length - 1 ];

if ( ! element ) {
return;
}
Expand Down Expand Up @@ -117,11 +114,20 @@ export function useInBetweenInserter() {
return;
}

showInsertionPoint(
rootClientId,
getBlockIndex( clientId, rootClientId ),
{ __unstableWithInserter: true }
);
const index = getBlockIndex( clientId, rootClientId );

// Don't show the in-between inserter before the first block in
// the list (preserves the original behaviour).
if ( index === 0 ) {
if ( isBlockInsertionPointVisible() ) {
hideInsertionPoint();
}
return;
}

showInsertionPoint( rootClientId, index, {
__unstableWithInserter: true,
} );
}

node.addEventListener( 'mousemove', onMouseMove );
Expand All @@ -132,7 +138,6 @@ export function useInBetweenInserter() {
},
[
openRef,
getBlockInsertionPoint,
getBlockListSettings,
getBlockRootClientId,
getBlockIndex,
Expand Down

0 comments on commit e54afb8

Please sign in to comment.