From e51e72c676492a984d0becd7053bd3dea7a70444 Mon Sep 17 00:00:00 2001 From: Mark Tolmacs Date: Wed, 16 Apr 2025 19:11:11 +0200 Subject: [PATCH] Another half of actionFinalize on arrow endpoint drag --- .../excalidraw/actions/actionFinalize.tsx | 31 ++++++++++++++----- packages/math/src/point.ts | 3 +- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/packages/excalidraw/actions/actionFinalize.tsx b/packages/excalidraw/actions/actionFinalize.tsx index 7ab677f02f..63751d1f6f 100644 --- a/packages/excalidraw/actions/actionFinalize.tsx +++ b/packages/excalidraw/actions/actionFinalize.tsx @@ -17,6 +17,12 @@ import { isPathALoop } from "@excalidraw/element/shapes"; import { isInvisiblySmallElement } from "@excalidraw/element/sizeHelpers"; +import type { + ExcalidrawElement, + ExcalidrawLinearElement, + NonDeleted, +} from "@excalidraw/element/types"; + import { t } from "../i18n"; import { resetCursor } from "../cursor"; import { done } from "../components/icons"; @@ -84,13 +90,22 @@ export const actionFinalize = register({ focusContainer(); } - const element = appState.multiElement - ? appState.multiElement - : appState.newElement?.type === "freedraw" - ? appState.newElement - : isBindingElement(appState.newElement) - ? appState.newElement - : null; + let element: NonDeleted | null = null; + if (appState.multiElement) { + element = appState.multiElement; + } else if ( + appState.newElement?.type === "freedraw" || + isBindingElement(appState.newElement) + ) { + element = appState.newElement; + } else if (Object.keys(appState.selectedElementIds).length === 1) { + const candidate = elementsMap.get( + Object.keys(appState.selectedElementIds)[0], + ) as NonDeleted | undefined; + if (candidate) { + element = candidate; + } + } if (element) { // pen and mouse have hover @@ -112,7 +127,7 @@ export const actionFinalize = register({ if (isInvisiblySmallElement(element)) { // TODO: #7348 in theory this gets recorded by the store, so the invisible elements could be restored by the undo/redo, which might be not what we would want - newElements = newElements.filter((el) => el.id !== element.id); + newElements = newElements.filter((el) => el.id !== element!.id); } // If the multi point line closes the loop, diff --git a/packages/math/src/point.ts b/packages/math/src/point.ts index b6054a10a3..1e80d28d7f 100644 --- a/packages/math/src/point.ts +++ b/packages/math/src/point.ts @@ -91,9 +91,10 @@ export function isPoint(p: unknown): p is LocalPoint | GlobalPoint { export function pointsEqual( a: Point, b: Point, + threshold: number = PRECISION, ): boolean { const abs = Math.abs; - return abs(a[0] - b[0]) < PRECISION && abs(a[1] - b[1]) < PRECISION; + return abs(a[0] - b[0]) < threshold && abs(a[1] - b[1]) < threshold; } /**