diff --git a/packages/element/src/binding.ts b/packages/element/src/binding.ts index bf6767edb..ad0ebe0e2 100644 --- a/packages/element/src/binding.ts +++ b/packages/element/src/binding.ts @@ -410,41 +410,36 @@ export const maybeSuggestBindingsForLinearElementAtCoords = ( // During line creation the start binding hasn't been written yet // into `linearElement` oppositeBindingBoundElement?: ExcalidrawBindableElement | null, -): ExcalidrawBindableElement[] => { - if (!pointerCoords.length) { - return []; - } +): ExcalidrawBindableElement[] => + Array.from( + pointerCoords.reduce( + (acc: Set>, coords) => { + const hoveredBindableElement = getHoveredElementForBinding( + coords, + scene.getNonDeletedElements(), + scene.getNonDeletedElementsMap(), + zoom, + isElbowArrow(linearElement), + isElbowArrow(linearElement), + ); - const suggestedBindings = pointerCoords.reduce( - (acc: Set>, coords) => { - const hoveredBindableElement = getHoveredElementForBinding( - coords, - scene.getNonDeletedElements(), - scene.getNonDeletedElementsMap(), - zoom, - isElbowArrow(linearElement), - isElbowArrow(linearElement), - ); + if ( + hoveredBindableElement != null && + !isLinearElementSimpleAndAlreadyBound( + linearElement, + oppositeBindingBoundElement?.id, + hoveredBindableElement, + ) + ) { + acc.add(hoveredBindableElement); + } - if ( - hoveredBindableElement != null && - !isLinearElementSimpleAndAlreadyBound( - linearElement, - oppositeBindingBoundElement?.id, - hoveredBindableElement, - ) - ) { - acc.add(hoveredBindableElement); - } - - return acc; - }, - new Set() as Set>, + return acc; + }, + new Set() as Set>, + ), ); - return Array.from(suggestedBindings); -}; - export const maybeBindLinearElement = ( linearElement: NonDeleted, appState: AppState, diff --git a/packages/element/src/linearElementEditor.ts b/packages/element/src/linearElementEditor.ts index b6dcdcef9..e29213233 100644 --- a/packages/element/src/linearElementEditor.ts +++ b/packages/element/src/linearElementEditor.ts @@ -18,6 +18,7 @@ import { getGridPoint, invariant, tupleToCoors, + viewportCoordsToSceneCoords, } from "@excalidraw/common"; import type { Store } from "@excalidraw/element"; @@ -458,6 +459,7 @@ export class LinearElementEditor { ): LinearElementEditor { const elementsMap = scene.getNonDeletedElementsMap(); const elements = scene.getNonDeletedElements(); + const pointerCoords = viewportCoordsToSceneCoords(event, appState); const { elementId, selectedPointsIndices, isDragging, pointerDownState } = editingLinearElement; @@ -501,13 +503,7 @@ export class LinearElementEditor { const bindingElement = isBindingEnabled(appState) ? getHoveredElementForBinding( - tupleToCoors( - LinearElementEditor.getPointAtIndexGlobalCoordinates( - element, - selectedPoint!, - elementsMap, - ), - ), + pointerCoords, elements, elementsMap, appState.zoom, diff --git a/packages/excalidraw/components/App.tsx b/packages/excalidraw/components/App.tsx index b71f0fcad..974e98781 100644 --- a/packages/excalidraw/components/App.tsx +++ b/packages/excalidraw/components/App.tsx @@ -9755,7 +9755,8 @@ class App extends React.Component { } if ( - pointerDownState.drag.hasOccurred || + (pointerDownState.drag.hasOccurred && + !this.state.selectedLinearElement) || isResizing || isRotating || isCropping