Skip to content

Commit

Permalink
Improve rootClientId comparison in useBlockDropZone (#24307)
Browse files Browse the repository at this point in the history
* Default to an empty string for targetRootClientId

* Fix typo
  • Loading branch information
talldan authored Aug 1, 2020
1 parent 9888748 commit 5526d0c
Showing 1 changed file with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,11 @@ function parseDropEvent( event ) {
*/
export default function useBlockDropZone( {
element,
rootClientId: targetRootClientId,
// An undefined value represents a top-level block. Default to an empty
// string for this so that `targetRootClientId` can be easily compared to
// values returned by the `getRootBlockClientId` selector, which also uses
// an empty string to represent top-level blocks.
rootClientId: targetRootClientId = '',
} ) {
const [ targetBlockIndex, setTargetBlockIndex ] = useState( null );

Expand Down Expand Up @@ -285,16 +289,11 @@ export default function useBlockDropZone( {
return;
}

const isAtSameLevel =
sourceRootClientId === targetRootClientId ||
( sourceRootClientId === '' &&
targetRootClientId === undefined );

const draggedBlockCount = sourceClientIds.length;

// If the block is kept at the same level and moved downwards,
// subtract to take into account that the blocks being dragged
// were removed from the block list.
const isAtSameLevel = sourceRootClientId === targetRootClientId;
const draggedBlockCount = sourceClientIds.length;
const insertIndex =
isAtSameLevel && sourceBlockIndex < targetBlockIndex
? targetBlockIndex - draggedBlockCount
Expand Down

0 comments on commit 5526d0c

Please sign in to comment.