diff --git a/packages/common/src/utils.ts b/packages/common/src/utils.ts index e90d2d82e9..35638fc236 100644 --- a/packages/common/src/utils.ts +++ b/packages/common/src/utils.ts @@ -1,6 +1,11 @@ import { average } from "@excalidraw/math"; +import { isImageElement } from "@excalidraw/element"; -import type { FontFamilyValues, FontString } from "@excalidraw/element/types"; +import type { + ExcalidrawBindableElement, + FontFamilyValues, + FontString, +} from "@excalidraw/element/types"; import type { ActiveTool, @@ -562,6 +567,9 @@ export const isTransparent = (color: string) => { ); }; +export const isAlwaysInsideBinding = (element: ExcalidrawBindableElement) => + isImageElement(element); + export type ResolvablePromise = Promise & { resolve: [T] extends [undefined] ? (value?: MaybePromise>) => void diff --git a/packages/element/src/binding.ts b/packages/element/src/binding.ts index 60a7c27c0c..dd82c3169a 100644 --- a/packages/element/src/binding.ts +++ b/packages/element/src/binding.ts @@ -1,4 +1,10 @@ -import { KEYS, arrayToMap, invariant, tupleToCoors } from "@excalidraw/common"; +import { + KEYS, + arrayToMap, + invariant, + isAlwaysInsideBinding, + tupleToCoors, +} from "@excalidraw/common"; import { lineSegment, @@ -318,7 +324,10 @@ const bindingStrategyForEndpointDragging = ( // If the global bind mode is in free binding mode, just bind // where the pointer is and keep the other end intact - if (globalBindMode === "inside") { + if ( + globalBindMode === "inside" || + (hovered && isAlwaysInsideBinding(hovered)) + ) { current = hovered ? { element: hovered, @@ -393,7 +402,6 @@ const bindingStrategyForEndpointDragging = ( } // The dragged point is inside the hovered bindable element else { - console.log(oppositeBinding); // The opposite binding is on the same element // eslint-disable-next-line no-lonely-if if (oppositeBinding) {