fix: Jump inside

Signed-off-by: Mark Tolmacs <mark@lazycat.hu>
This commit is contained in:
Mark Tolmacs
2026-03-26 17:10:45 +00:00
parent 3b0a6af46f
commit 50749b8119
3 changed files with 80 additions and 50 deletions
+49 -31
View File
@@ -694,6 +694,7 @@ const getBindingStrategyForDraggingBindingElementEndpoints_simple = (
localPoint, localPoint,
elementsMap, elementsMap,
); );
const hit = getHoveredElementForBinding( const hit = getHoveredElementForBinding(
globalPoint, globalPoint,
elements, elements,
@@ -749,7 +750,8 @@ const getBindingStrategyForDraggingBindingElementEndpoints_simple = (
: // NOTE: Can only affect the start point because new arrows always drag the end point : // NOTE: Can only affect the start point because new arrows always drag the end point
opts?.newArrow opts?.newArrow
? appState.selectedLinearElement!.initialState.origin! ? appState.selectedLinearElement!.initialState.origin!
: LinearElementEditor.getPointAtIndexGlobalCoordinates( : appState.selectedLinearElement?.initialState.altFocusPoint ||
LinearElementEditor.getPointAtIndexGlobalCoordinates(
arrow, arrow,
0, 0,
elementsMap, elementsMap,
@@ -760,7 +762,8 @@ const getBindingStrategyForDraggingBindingElementEndpoints_simple = (
element: hit, element: hit,
focusPoint: endDragged focusPoint: endDragged
? globalPoint ? globalPoint
: LinearElementEditor.getPointAtIndexGlobalCoordinates( : appState.selectedLinearElement?.initialState.altFocusPoint ||
LinearElementEditor.getPointAtIndexGlobalCoordinates(
arrow, arrow,
-1, -1,
elementsMap, elementsMap,
@@ -833,41 +836,56 @@ const getBindingStrategyForDraggingBindingElementEndpoints_simple = (
overrideShouldTestInside: true, overrideShouldTestInside: true,
}); });
const otherPointWasInsideAtStart = const otherPointWasInsideAtStart =
!appState.selectedLinearElement?.initialState.altFocusPoint || appState.selectedLinearElement?.initialState
pointsEqual( .arrowOtherEndpointInitialBinding?.mode === "inside";
appState.selectedLinearElement.initialState.altFocusPoint,
otherEndpoint,
);
const otherNeverOverride = opts?.newArrow const otherNeverOverride = opts?.newArrow
? appState.selectedLinearElement?.initialState.arrowStartIsInside ? appState.selectedLinearElement?.initialState.arrowStartIsInside
: otherBinding?.mode === "inside" && otherPointWasInsideAtStart; : otherBinding?.mode === "inside" && otherPointWasInsideAtStart;
const other: BindingStrategy = !otherNeverOverride
? otherBindableElement && let other: BindingStrategy = { mode: undefined };
if (!otherNeverOverride) {
if (
otherBinding?.mode === "inside" &&
!otherPointWasInsideAtStart &&
otherBindableElement
) {
other = {
mode: "orbit",
element: otherBindableElement,
focusPoint: getGlobalFixedPointForBindableElement(
otherBinding.fixedPoint,
otherBindableElement,
elementsMap,
),
};
} else if (
otherBindableElement &&
!otherFocusPointIsInElement && !otherFocusPointIsInElement &&
!pointIsCloseToOtherElement && !pointIsCloseToOtherElement &&
appState.selectedLinearElement?.initialState.altFocusPoint appState.selectedLinearElement?.initialState.altFocusPoint
? { ) {
mode: "orbit", other = {
element: otherBindableElement, mode: "orbit",
focusPoint: appState.selectedLinearElement.initialState.altFocusPoint, element: otherBindableElement,
} focusPoint: appState.selectedLinearElement.initialState.altFocusPoint,
: opts?.angleLocked && otherBindableElement };
? { } else if (opts?.angleLocked && otherBindableElement) {
mode: "orbit", other = {
element: otherBindableElement, mode: "orbit",
focusPoint: element: otherBindableElement,
projectFixedPointOntoDiagonal( focusPoint:
arrow, projectFixedPointOntoDiagonal(
otherEndpoint, arrow,
otherBindableElement, otherEndpoint,
startDragged ? "end" : "start", otherBindableElement,
elementsMap, startDragged ? "end" : "start",
appState.zoom, elementsMap,
appState.isMidpointSnappingEnabled, appState.zoom,
) || otherEndpoint, appState.isMidpointSnappingEnabled,
} ) || otherEndpoint,
: { mode: undefined } };
: { mode: undefined }; }
}
return { return {
start: startDragged ? current : other, start: startDragged ? current : other,
+27 -19
View File
@@ -141,6 +141,7 @@ export class LinearElementEditor {
}; };
arrowStartIsInside: boolean; arrowStartIsInside: boolean;
altFocusPoint: Readonly<GlobalPoint> | null; altFocusPoint: Readonly<GlobalPoint> | null;
arrowOtherEndpointInitialBinding: FixedPointBinding | null;
}>; }>;
/** whether you're dragging a point */ /** whether you're dragging a point */
@@ -193,6 +194,7 @@ export class LinearElementEditor {
added: false, added: false,
}, },
arrowStartIsInside: false, arrowStartIsInside: false,
arrowOtherEndpointInitialBinding: null,
altFocusPoint: null, altFocusPoint: null,
}; };
this.hoverPointIndex = -1; this.hoverPointIndex = -1;
@@ -764,6 +766,7 @@ export class LinearElementEditor {
...editingLinearElement.initialState, ...editingLinearElement.initialState,
origin: null, origin: null,
arrowStartIsInside: false, arrowStartIsInside: false,
arrowOtherEndpointInitialBinding: null,
}, },
}; };
} }
@@ -1085,6 +1088,10 @@ export class LinearElementEditor {
!!app.state.newElement && !!app.state.newElement &&
(app.state.bindMode === "inside" || app.state.bindMode === "skip"), (app.state.bindMode === "inside" || app.state.bindMode === "skip"),
altFocusPoint: null, altFocusPoint: null,
arrowOtherEndpointInitialBinding:
linearElementEditor.selectedPointsIndices?.includes(0)
? element.startBinding
: element.endBinding,
}, },
selectedPointsIndices: [element.points.length - 1], selectedPointsIndices: [element.points.length - 1],
lastUncommittedPoint: null, lastUncommittedPoint: null,
@@ -1147,6 +1154,10 @@ export class LinearElementEditor {
!!app.state.newElement && !!app.state.newElement &&
(app.state.bindMode === "inside" || app.state.bindMode === "skip"), (app.state.bindMode === "inside" || app.state.bindMode === "skip"),
altFocusPoint: null, altFocusPoint: null,
arrowOtherEndpointInitialBinding:
linearElementEditor.selectedPointsIndices?.includes(0)
? element.startBinding
: element.endBinding,
}, },
selectedPointsIndices: nextSelectedPointsIndices, selectedPointsIndices: nextSelectedPointsIndices,
pointerOffset: targetPoint pointerOffset: targetPoint
@@ -2409,22 +2420,21 @@ const pointDraggingUpdates = (
)! as ExcalidrawBindableElement) )! as ExcalidrawBindableElement)
: null; : null;
const endLocalPoint = startIsDraggingOverEndElement const endLocalPoint =
? nextArrow.points[nextArrow.points.length - 1] endIsDraggingOverStartElement &&
: endIsDraggingOverStartElement && app.state.bindMode !== "inside" &&
app.state.bindMode !== "inside" && getFeatureFlag("COMPLEX_BINDINGS")
getFeatureFlag("COMPLEX_BINDINGS") ? nextArrow.points[0]
? nextArrow.points[0] : endBindable
: endBindable ? updateBoundPoint(
? updateBoundPoint( nextArrow,
nextArrow, "endBinding",
"endBinding", nextArrow.endBinding,
nextArrow.endBinding, endBindable,
endBindable, elementsMap,
elementsMap, endIsDragged,
endIsDragged, ) || nextArrow.points[nextArrow.points.length - 1]
) || nextArrow.points[nextArrow.points.length - 1] : nextArrow.points[nextArrow.points.length - 1];
: nextArrow.points[nextArrow.points.length - 1];
// We need to keep the simulated next arrow up-to-date, because // We need to keep the simulated next arrow up-to-date, because
// updateBoundPoint looks at the opposite point // updateBoundPoint looks at the opposite point
@@ -2458,13 +2468,11 @@ const pointDraggingUpdates = (
: nextArrow.points[0]; : nextArrow.points[0];
const endChanged = const endChanged =
!startIsDraggingOverEndElement &&
!( !(
endIsDraggingOverStartElement && endIsDraggingOverStartElement &&
app.state.bindMode !== "inside" && app.state.bindMode !== "inside" &&
getFeatureFlag("COMPLEX_BINDINGS") getFeatureFlag("COMPLEX_BINDINGS")
) && ) && !!endBindable;
!!endBindable;
const startChanged = const startChanged =
pointDistance(startLocalPoint, nextArrow.points[0]) !== 0; pointDistance(startLocalPoint, nextArrow.points[0]) !== 0;
@@ -8663,6 +8663,7 @@ exports[`regression tests > key 5 selects arrow tool > [end of test] appState 1`
"hoveredFocusPointBinding": null, "hoveredFocusPointBinding": null,
"initialState": { "initialState": {
"altFocusPoint": null, "altFocusPoint": null,
"arrowOtherEndpointInitialBinding": null,
"arrowStartIsInside": false, "arrowStartIsInside": false,
"lastClickedPoint": -1, "lastClickedPoint": -1,
"origin": null, "origin": null,
@@ -8895,6 +8896,7 @@ exports[`regression tests > key 6 selects line tool > [end of test] appState 1`]
"hoveredFocusPointBinding": null, "hoveredFocusPointBinding": null,
"initialState": { "initialState": {
"altFocusPoint": null, "altFocusPoint": null,
"arrowOtherEndpointInitialBinding": null,
"arrowStartIsInside": false, "arrowStartIsInside": false,
"lastClickedPoint": -1, "lastClickedPoint": -1,
"origin": null, "origin": null,
@@ -9317,6 +9319,7 @@ exports[`regression tests > key a selects arrow tool > [end of test] appState 1`
"hoveredFocusPointBinding": null, "hoveredFocusPointBinding": null,
"initialState": { "initialState": {
"altFocusPoint": null, "altFocusPoint": null,
"arrowOtherEndpointInitialBinding": null,
"arrowStartIsInside": false, "arrowStartIsInside": false,
"lastClickedPoint": -1, "lastClickedPoint": -1,
"origin": null, "origin": null,
@@ -9729,6 +9732,7 @@ exports[`regression tests > key l selects line tool > [end of test] appState 1`]
"hoveredFocusPointBinding": null, "hoveredFocusPointBinding": null,
"initialState": { "initialState": {
"altFocusPoint": null, "altFocusPoint": null,
"arrowOtherEndpointInitialBinding": null,
"arrowStartIsInside": false, "arrowStartIsInside": false,
"lastClickedPoint": -1, "lastClickedPoint": -1,
"origin": null, "origin": null,