From b63cd86cd61f32c5df043a5b4bea9d3da9538c6c Mon Sep 17 00:00:00 2001 From: Mark Tolmacs Date: Tue, 15 Apr 2025 17:15:53 +0200 Subject: [PATCH] Fix target point well inside shape issues Signed-off-by: Mark Tolmacs --- packages/element/src/binding.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/element/src/binding.ts b/packages/element/src/binding.ts index cf7bde4719..927f55ae08 100644 --- a/packages/element/src/binding.ts +++ b/packages/element/src/binding.ts @@ -27,7 +27,9 @@ import { PRECISION, } from "@excalidraw/math"; -import { isPointOnShape } from "@excalidraw/utils/collision"; +import { isPointInShape, isPointOnShape } from "@excalidraw/utils/collision"; + +import { getEllipseShape, getPolygonShape } from "@excalidraw/utils/shape"; import type { LocalPoint, Radians } from "@excalidraw/math"; @@ -909,8 +911,14 @@ const getDistanceForBinding = ( bindableElement.height, zoom, ); + const isInside = isPointInShape( + point, + bindableElement.type === "ellipse" + ? getEllipseShape(bindableElement) + : getPolygonShape(bindableElement), + ); - return distance > bindDistance ? null : distance; + return distance > bindDistance && !isInside ? null : distance; }; export const bindPointToSnapToElementOutline = (