From 0b0846bd8e4e32c804b35fdd85728e3e8dc441de Mon Sep 17 00:00:00 2001 From: Aakansha Doshi Date: Thu, 1 Sep 2022 18:03:49 +0530 Subject: [PATCH] fix index --- src/element/linearElementEditor.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/element/linearElementEditor.ts b/src/element/linearElementEditor.ts index 767c71bbe..39eb7737a 100644 --- a/src/element/linearElementEditor.ts +++ b/src/element/linearElementEditor.ts @@ -791,19 +791,20 @@ export class LinearElementEditor { const pointHandles = LinearElementEditor.getPointsGlobalCoordinates(element); - let idx = linearElementEditor.visiblePointIndexes.length; + let counter = linearElementEditor.visiblePointIndexes.length; // loop from right to left because points on the right are rendered over // points on the left, thus should take precedence when clicking, if they // overlap - while (--idx > 0) { - const point = pointHandles[linearElementEditor.visiblePointIndexes[idx]]; + while (--counter >= 0) { + const index = linearElementEditor.visiblePointIndexes[counter]; + const point = pointHandles[index]; if ( distance2d(x, y, point[0], point[1]) * zoom.value < // +1px to account for outline stroke LinearElementEditor.POINT_HANDLE_SIZE + 1 ) { - return idx; + return index; } } return -1;