feat: Distance based candidates

Signed-off-by: Mark Tolmacs <mark@lazycat.hu>
This commit is contained in:
Mark Tolmacs
2026-05-07 22:23:30 +02:00
parent b2b2815954
commit a727f6c5e2
+9 -3
View File
@@ -359,12 +359,18 @@ export const getHoveredElementForBinding = (
return candidateElements[0]; return candidateElements[0];
} }
// Prefer smaller shapes // Prefer closer shapes
return candidateElements return candidateElements
.sort( .sort(
(a, b) => b.width ** 2 + b.height ** 2 - (a.width ** 2 + a.height ** 2), (a, b) =>
(isPointInElement(point, a, elementsMap)
? Infinity
: distanceToElement(a, elementsMap, point)) -
(isPointInElement(point, b, elementsMap)
? Infinity
: distanceToElement(b, elementsMap, point)),
) )
.pop() as NonDeleted<ExcalidrawBindableElement>; .shift() as NonDeleted<ExcalidrawBindableElement>;
}; };
export const getHoveredElementForFocusPoint = ( export const getHoveredElementForFocusPoint = (