fix: Preserve alternate orbit focus point during drag

This commit is contained in:
dwelle
2025-11-10 13:44:23 +01:00
committed by Mark Tolmacs
parent 438297f083
commit c412e81e27
2 changed files with 27 additions and 6 deletions

View File

@@ -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<GlobalPoint>(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<GlobalPoint>(element.x, element.y),
startBindingElement,
altFocusPointBindableElement,
"start",
elementsMap,
)

View File

@@ -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;
};