From 04ce887151ff23ca35b6d1dc3220504860ae28e7 Mon Sep 17 00:00:00 2001 From: Daniel Richards Date: Fri, 24 Jul 2020 13:03:22 +0800 Subject: [PATCH 1/2] Offset insertion index by number of blocks dragged --- .../block-editor/src/components/use-block-drop-zone/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/block-editor/src/components/use-block-drop-zone/index.js b/packages/block-editor/src/components/use-block-drop-zone/index.js index de2368d333ca31..96752d8126ab97 100644 --- a/packages/block-editor/src/components/use-block-drop-zone/index.js +++ b/packages/block-editor/src/components/use-block-drop-zone/index.js @@ -290,11 +290,13 @@ export default function useBlockDropZone( { ( sourceRootClientId === '' && targetRootClientId === undefined ); + const draggedBlockCount = sourceClientIds.length; + // If the block is kept at the same level and moved downwards, // subtract to account for blocks shifting upward to occupy its old position. const insertIndex = isAtSameLevel && sourceBlockIndex < targetBlockIndex - ? targetBlockIndex - 1 + ? targetBlockIndex - draggedBlockCount : targetBlockIndex; moveBlocksToPosition( From 57f341efd1c2a6dde753e6f0e2f0ecc38721b3cf Mon Sep 17 00:00:00 2001 From: Daniel Richards Date: Fri, 24 Jul 2020 13:09:05 +0800 Subject: [PATCH 2/2] Update comment --- .../block-editor/src/components/use-block-drop-zone/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/block-editor/src/components/use-block-drop-zone/index.js b/packages/block-editor/src/components/use-block-drop-zone/index.js index 96752d8126ab97..7ff5496acca120 100644 --- a/packages/block-editor/src/components/use-block-drop-zone/index.js +++ b/packages/block-editor/src/components/use-block-drop-zone/index.js @@ -293,7 +293,8 @@ export default function useBlockDropZone( { const draggedBlockCount = sourceClientIds.length; // If the block is kept at the same level and moved downwards, - // subtract to account for blocks shifting upward to occupy its old position. + // subtract to take into account that the blocks being dragged + // were removed from the block list. const insertIndex = isAtSameLevel && sourceBlockIndex < targetBlockIndex ? targetBlockIndex - draggedBlockCount