From 4fa425ac29051ac706422622479e2c62be9a9699 Mon Sep 17 00:00:00 2001 From: Kerry Liu Date: Wed, 11 Aug 2021 14:26:36 -0700 Subject: [PATCH] wip fix ordering --- .../src/components/list-view/index.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/block-editor/src/components/list-view/index.js b/packages/block-editor/src/components/list-view/index.js index 9e34be153c848c..96c6428b3ebb8d 100644 --- a/packages/block-editor/src/components/list-view/index.js +++ b/packages/block-editor/src/components/list-view/index.js @@ -198,19 +198,21 @@ export default function ListView( { if ( ! lastTarget.current ) { return; } - const targetId = lastTarget.current.targetPosition.clientId; - const clientId = lastTarget.current.clientId; - const target = findCurrentPosition( clientIdsTree, targetId ); - const current = findCurrentPosition( - clientIdsTree, - lastTarget.clientId + const { targetPosition, clientId, movingDown } = lastTarget.current; + const targetId = targetPosition.clientId; + const target = findCurrentPosition( + removeItemFromTree( clientIdsTree, clientId ), + targetId ); + const current = findCurrentPosition( clientIdsTree, clientId ); + + const targetIndex = movingDown ? target.index + 1 : target.index; setDropped( true ); moveBlocksToPosition( [ clientId ], current.parentId, target.parentId, - target.index + targetIndex ); lastTarget.current = null; //TODO: see if waiting for the state update hides unecessary layout changes. @@ -237,6 +239,7 @@ export default function ListView( { lastTarget.current = { clientId, targetPosition, + movingDown, }; const newTree = addItemToTree( removeItemFromTree( clientIdsTree, clientId ),