Skip to content

Commit

Permalink
wip fix false positives when dragging outside of bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
gwwar committed Aug 13, 2021
1 parent 8276fce commit 8861436
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/block-editor/src/components/list-view/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ export default function ListView( {
//TODO: support add to container
//TODO: support add to child container
//TODO: simplify state and code
//TODO: either constrain the drag area to the max number of items, or test if we're hovering over the midpoint of next targets
const { clientId } = block;
const ITEM_HEIGHT = 36;

Expand All @@ -262,6 +261,19 @@ export default function ListView( {

const direction = v > 0 ? DOWN : UP;

const draggingUpPastBounds =
positions[ listPosition + 1 ] === undefined &&
direction === UP &&
translate > 0;
const draggingDownPastBounds =
listPosition === 0 && direction === DOWN && translate < 0;

if ( draggingUpPastBounds || draggingDownPastBounds ) {
// If we've dragged past all items with the first or last item, don't start checking for potential swaps
// until we're near other items
return;
}

if ( Math.abs( translate ) > ITEM_HEIGHT / 2 ) {
const position = positions[ listPosition ];

Expand Down

0 comments on commit 8861436

Please sign in to comment.