diff --git a/packages/element/src/linearElementEditor.ts b/packages/element/src/linearElementEditor.ts index 38dc3d5c6a..3b0484f2cc 100644 --- a/packages/element/src/linearElementEditor.ts +++ b/packages/element/src/linearElementEditor.ts @@ -410,7 +410,9 @@ export class LinearElementEditor { initialState: { ...linearElementEditor.initialState, altFocusPoint: - !linearElementEditor.initialState.altFocusPoint && startBindingElement + !linearElementEditor.initialState.altFocusPoint && + startBindingElement && + updates?.suggestedBinding?.id !== startBindingElement.id ? projectFixedPointOntoDiagonal( element, pointFrom(element.x, element.y), @@ -610,6 +612,22 @@ export class LinearElementEditor { (elementsMap.get( element.startBinding.elementId, ) as ExcalidrawBindableElement | null); + const endBindingElement = + isBindingElement(element) && + element.endBinding && + (elementsMap.get( + element.endBinding.elementId, + ) as ExcalidrawBindableElement | null); + const altFocusPointBindableElement = + endIsSelected && // The "other" end (i.e. "end") is dragged + startBindingElement && + updates?.suggestedBinding?.id !== startBindingElement.id // The end point is not hovering the start bindable + it's binding gap + ? startBindingElement + : startIsSelected && // The "other" end (i.e. "start") is dragged + endBindingElement && + updates?.suggestedBinding?.id !== endBindingElement.id // The start point is not hovering the end bindable + it's binding gap + ? endBindingElement + : null; const newLinearElementEditor = { ...linearElementEditor, @@ -618,11 +636,13 @@ export class LinearElementEditor { ...linearElementEditor.initialState, lastClickedPoint: newLastClickedPoint, altFocusPoint: - !linearElementEditor.initialState.altFocusPoint && startBindingElement + !linearElementEditor.initialState.altFocusPoint && // We only set it once per arrow drag + isBindingElement(element) && + altFocusPointBindableElement ? projectFixedPointOntoDiagonal( element, pointFrom(element.x, element.y), - startBindingElement, + altFocusPointBindableElement, "start", elementsMap, ) diff --git a/packages/element/src/utils.ts b/packages/element/src/utils.ts index f97428a8bc..673dfefd16 100644 --- a/packages/element/src/utils.ts +++ b/packages/element/src/utils.ts @@ -1,4 +1,5 @@ import { + debugDrawLine, DEFAULT_ADAPTIVE_RADIUS, DEFAULT_PROPORTIONAL_RADIUS, invariant, @@ -598,9 +599,9 @@ export const projectFixedPointOntoDiagonal = ( p = p1 || p2 || null; } - // debugDrawLine(diagonalOne, { color: "purple", permanent: true }); - // debugDrawLine(diagonalTwo, { color: "purple", permanent: true }); - // debugDrawLine(intersector, { color: "orange", permanent: true }); + debugDrawLine(diagonalOne, { color: "purple", permanent: false }); + debugDrawLine(diagonalTwo, { color: "purple", permanent: false }); + debugDrawLine(intersector, { color: "orange", permanent: false }); return p && isPointInElement(p, element, elementsMap) ? p : null; };