From 508d4c36813c6363aebe6abd295d8aae95074044 Mon Sep 17 00:00:00 2001 From: Mark Tolmacs Date: Thu, 8 May 2025 11:17:03 +0200 Subject: [PATCH] Fix condition where linear and freedraw cannot be unselected --- packages/utils/src/collision.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/utils/src/collision.ts b/packages/utils/src/collision.ts index 0ffd1b1ec..6f49d4b26 100644 --- a/packages/utils/src/collision.ts +++ b/packages/utils/src/collision.ts @@ -14,6 +14,10 @@ import { elementCenterPoint } from "@excalidraw/common"; import { distanceToElement } from "@excalidraw/element/distance"; +import { isLinearElement } from "@excalidraw/excalidraw"; +import { isFreeDrawElement } from "@excalidraw/element/typeChecks"; +import { isPathALoop } from "@excalidraw/element/shapes"; + import type { ExcalidrawElement } from "@excalidraw/element/types"; import type { Curve } from "@excalidraw/math"; @@ -36,6 +40,14 @@ export const isPointInShape = ( point: GlobalPoint, element: ExcalidrawElement, ) => { + if ( + (isLinearElement(element) || isFreeDrawElement(element)) && + !isPathALoop(element.points) + ) { + // There isn't any "inside" for a non-looping path + return false; + } + const intersections = intersectElementWithLineSegment( element, lineSegment(elementCenterPoint(element), point),