Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions src/cdk/drag-drop/sorting/single-axis-sort-strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,24 @@ export class SingleAxisSortStrategy implements DropListSortStrategy {
* out automatically.
*/
enter(item: DragRef, pointerX: number, pointerY: number, index?: number): void {
const activeDraggables = this._activeDraggables;
const currentIndex = activeDraggables.indexOf(item);
const placeholder = item.getPlaceholderElement();

// Since the item may be in the `activeDraggables` already (e.g. if the user dragged it
// into another container and back again), we have to ensure that it isn't duplicated.
// Note that we need to run this early so the code further below isn't thrown off.
if (currentIndex > -1) {
activeDraggables.splice(currentIndex, 1);
}

const newIndex =
index == null || index < 0
? // We use the coordinates of where the item entered the drop
// zone to figure out at which index it should be inserted.
this._getItemIndexFromPointerPosition(item, pointerX, pointerY)
: index;

const activeDraggables = this._activeDraggables;
const currentIndex = activeDraggables.indexOf(item);
const placeholder = item.getPlaceholderElement();
let newPositionReference: DragRef | undefined = activeDraggables[newIndex];

// If the item at the new position is the same as the item that is being dragged,
Expand All @@ -197,12 +205,6 @@ export class SingleAxisSortStrategy implements DropListSortStrategy {
newPositionReference = activeDraggables[0];
}

// Since the item may be in the `activeDraggables` already (e.g. if the user dragged it
// into another container and back again), we have to ensure that it isn't duplicated.
if (currentIndex > -1) {
activeDraggables.splice(currentIndex, 1);
}

// Don't use items that are being dragged as a reference, because
// their element has been moved down to the bottom of the body.
if (newPositionReference && !this._dragDropRegistry.isDragging(newPositionReference)) {
Expand Down
Loading