From c78cfc635ad70a1f44f2328e820e7cd9fa439a27 Mon Sep 17 00:00:00 2001 From: Toby Smith Date: Sun, 22 Aug 2021 13:40:33 +0100 Subject: [PATCH] fix(reorder-group): cap 'to' index when dragging off the end Previously the 'to' detail on item reorder events could be one too high if the item was dragged far enough --- core/src/components/reorder-group/reorder-group.tsx | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/core/src/components/reorder-group/reorder-group.tsx b/core/src/components/reorder-group/reorder-group.tsx index d3f43fd1336..62b3bdb80c7 100644 --- a/core/src/components/reorder-group/reorder-group.tsx +++ b/core/src/components/reorder-group/reorder-group.tsx @@ -245,17 +245,16 @@ export class ReorderGroup implements ComponentInterface { private itemIndexForTop(deltaY: number): number { const heights = this.cachedHeights; - let i = 0; // TODO: since heights is a sorted array of integers, we can do // speed up the search using binary search. Remember that linear-search is still // faster than binary-search for small arrays (<64) due CPU branch misprediction. - for (i = 0; i < heights.length; i++) { + for (let i = 0; i < heights.length; i++) { if (heights[i] > deltaY) { - break; + return i; } } - return i; + return heights.length - 1; } /********* DOM WRITE ********* */