Skip to content
This repository was archived by the owner on May 20, 2023. It is now read-only.

Commit 94f043b

Browse files
Googlernshahan
authored andcommitted
Restrict when a dragged item's target index is incremented or decremented.
The [moveTargetIndex] should only be incremented or decremented when the element being dragged over has shifted due to a previous drag (without a drop). PiperOrigin-RevId: 193207043
1 parent 8d3b6a9 commit 94f043b

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

lib/reorder_list/reorder_list.dart

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,12 +505,20 @@ class ReorderListComponent implements OnDestroy {
505505
var elementIndex = _getIndex(element);
506506

507507
var moveTargetIndex = elementIndex;
508+
// The [moveTargetIndex] needs to be incremented if the dragged item was
509+
// previously dragged up in the list (without a drop) and then dragged down
510+
// in the list to [element], which will have shifted position after the
511+
// first drag because it is in the range
512+
// [_currentMoveIndex, _moveSourceIndex).
513+
// The reverse situation requires decrementing the [moveTargetIndex].
508514
if (_currentMoveIndex < _moveSourceIndex &&
509-
elementIndex >= _currentMoveIndex) {
515+
elementIndex >= _currentMoveIndex &&
516+
elementIndex < _moveSourceIndex) {
510517
moveTargetIndex++;
511518
}
512519
if (_currentMoveIndex > _moveSourceIndex &&
513-
elementIndex <= _currentMoveIndex) {
520+
elementIndex <= _currentMoveIndex &&
521+
elementIndex > _moveSourceIndex) {
514522
moveTargetIndex--;
515523
}
516524

0 commit comments

Comments
 (0)