fix: Fixes

Signed-off-by: Mark Tolmacs <mark@lazycat.hu>
This commit is contained in:
Mark Tolmacs
2026-03-26 17:10:45 +00:00
parent 50749b8119
commit 5834e9f11f
3 changed files with 45 additions and 21 deletions
+18 -2
View File
@@ -27,6 +27,7 @@ import type {
ElementsMap, ElementsMap,
ExcalidrawArrowElement, ExcalidrawArrowElement,
ExcalidrawBindableElement, ExcalidrawBindableElement,
FixedPointBinding,
NonDeletedSceneElementsMap, NonDeletedSceneElementsMap,
PointsPositionUpdates, PointsPositionUpdates,
} from "../types"; } from "../types";
@@ -110,10 +111,17 @@ const focusPointUpdate = (
) => { ) => {
const pointUpdates = new Map(); const pointUpdates = new Map();
const originalAdjacentBinding =
appState.selectedLinearElement?.initialState
.arrowOtherEndpointInitialBinding;
const bindingField = isStartBinding ? "startBinding" : "endBinding"; const bindingField = isStartBinding ? "startBinding" : "endBinding";
const adjacentBindingField = isStartBinding ? "endBinding" : "startBinding"; const adjacentBindingField = isStartBinding ? "endBinding" : "startBinding";
let currentBinding = arrow[bindingField]; let currentBinding = arrow[bindingField];
let adjacentBinding = arrow[adjacentBindingField]; let adjacentBinding =
originalAdjacentBinding?.mode === "orbit" &&
arrow[adjacentBindingField]?.mode === "inside"
? originalAdjacentBinding
: arrow[adjacentBindingField];
// Update the dragged focus point related end // Update the dragged focus point related end
if (currentBinding && bindableElement) { if (currentBinding && bindableElement) {
@@ -339,6 +347,7 @@ export const handleFocusPointPointerDown = (
): { ): {
hitFocusPoint: "start" | "end" | null; hitFocusPoint: "start" | "end" | null;
pointerOffset: { x: number; y: number }; pointerOffset: { x: number; y: number };
arrowOtherEndpointInitialBinding: FixedPointBinding | null;
} => { } => {
const pointerPos = pointFrom( const pointerPos = pointFrom(
pointerDownState.origin.x, pointerDownState.origin.x,
@@ -376,6 +385,7 @@ export const handleFocusPointPointerDown = (
x: pointerPos[0] - focusPoint[0], x: pointerPos[0] - focusPoint[0],
y: pointerPos[1] - focusPoint[1], y: pointerPos[1] - focusPoint[1],
}, },
arrowOtherEndpointInitialBinding: arrow.endBinding,
}; };
} }
} }
@@ -411,6 +421,7 @@ export const handleFocusPointPointerDown = (
x: pointerPos[0] - focusPoint[0], x: pointerPos[0] - focusPoint[0],
y: pointerPos[1] - focusPoint[1], y: pointerPos[1] - focusPoint[1],
}, },
arrowOtherEndpointInitialBinding: arrow.startBinding,
}; };
} }
} }
@@ -419,13 +430,14 @@ export const handleFocusPointPointerDown = (
return { return {
hitFocusPoint: null, hitFocusPoint: null,
pointerOffset: { x: 0, y: 0 }, pointerOffset: { x: 0, y: 0 },
arrowOtherEndpointInitialBinding: null,
}; };
}; };
export const handleFocusPointPointerUp = ( export const handleFocusPointPointerUp = (
linearElementEditor: LinearElementEditor, linearElementEditor: LinearElementEditor,
scene: Scene, scene: Scene,
) => { ): { arrowOtherEndpointInitialBinding: FixedPointBinding | null } => {
invariant( invariant(
linearElementEditor.draggedFocusPointBinding, linearElementEditor.draggedFocusPointBinding,
"Must have a dragged focus point at pointer release", "Must have a dragged focus point at pointer release",
@@ -483,6 +495,10 @@ export const handleFocusPointPointerUp = (
], ],
}); });
} }
return {
arrowOtherEndpointInitialBinding: null,
};
}; };
export const handleFocusPointHover = ( export const handleFocusPointHover = (
+4 -8
View File
@@ -1088,10 +1088,7 @@ 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: arrowOtherEndpointInitialBinding: element.startBinding,
linearElementEditor.selectedPointsIndices?.includes(0)
? element.startBinding
: element.endBinding,
}, },
selectedPointsIndices: [element.points.length - 1], selectedPointsIndices: [element.points.length - 1],
lastUncommittedPoint: null, lastUncommittedPoint: null,
@@ -1154,10 +1151,9 @@ 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: arrowOtherEndpointInitialBinding: nextSelectedPointsIndices?.includes(0)
linearElementEditor.selectedPointsIndices?.includes(0) ? element.endBinding
? element.startBinding : element.startBinding,
: element.endBinding,
}, },
selectedPointsIndices: nextSelectedPointsIndices, selectedPointsIndices: nextSelectedPointsIndices,
pointerOffset: targetPoint pointerOffset: targetPoint
+23 -11
View File
@@ -8396,13 +8396,16 @@ class App extends React.Component<AppProps, AppState> {
) as any; ) as any;
if (arrow && isBindingElement(arrow)) { if (arrow && isBindingElement(arrow)) {
const { hitFocusPoint, pointerOffset } = const {
handleFocusPointPointerDown( hitFocusPoint,
arrow, pointerOffset,
pointerDownState, arrowOtherEndpointInitialBinding,
elementsMap, } = handleFocusPointPointerDown(
this.state, arrow,
); pointerDownState,
elementsMap,
this.state,
);
// If focus point is hit, update state and prevent element selection // If focus point is hit, update state and prevent element selection
if (hitFocusPoint) { if (hitFocusPoint) {
@@ -8412,6 +8415,10 @@ class App extends React.Component<AppProps, AppState> {
hoveredFocusPointBinding: hitFocusPoint, hoveredFocusPointBinding: hitFocusPoint,
draggedFocusPointBinding: hitFocusPoint, draggedFocusPointBinding: hitFocusPoint,
pointerOffset, pointerOffset,
initialState: {
...linearElementEditor.initialState,
arrowOtherEndpointInitialBinding,
},
}, },
}); });
return false; return false;
@@ -10524,14 +10531,19 @@ class App extends React.Component<AppProps, AppState> {
} }
if (this.state.selectedLinearElement.draggedFocusPointBinding) { if (this.state.selectedLinearElement.draggedFocusPointBinding) {
handleFocusPointPointerUp( const { arrowOtherEndpointInitialBinding } =
this.state.selectedLinearElement, handleFocusPointPointerUp(
this.scene, this.state.selectedLinearElement,
); this.scene,
);
this.setState({ this.setState({
selectedLinearElement: { selectedLinearElement: {
...this.state.selectedLinearElement, ...this.state.selectedLinearElement,
draggedFocusPointBinding: null, draggedFocusPointBinding: null,
initialState: {
...this.state.selectedLinearElement.initialState,
arrowOtherEndpointInitialBinding,
},
}, },
}); });
} else if ( } else if (