fix: Restore the midpoint snap radius for simple arrows

Merging the snapping and render midpoint code applied the elbow arrow
size-based thresholds (clamp(0.05 * size, 5, maxDistance)) to simple
arrows too, shrinking their snap radius from ~16px to 5px on typical
shapes (and basing side midpoints on the width). Use the binding distance
as the radius again, as on master; the render highlight still comes from
the same function. Restores master's history/move test expectations.

Claude Opus 5.5 (1M context), low reasoning effort
This commit is contained in:
dwelle committed 2026-09-23 17:43:00 +02:00
1 parent 29bcf7f77b
commit 04f339062f
5 files changed
+22 -32

No files matched your search

+2 -6
View File
@@ -724,14 +724,11 @@ const getSnappedMidpointIndexForSimpleArrow = (
element: ExcalidrawBindableElement,
point: GlobalPoint,
elementsMap: ElementsMap,
horizontalThreshold: number,
verticalThreshold: number,
threshold: number,
) => {
const baseMidpoints = getAllMidpoints(element, elementsMap);
for (let i = 0; i < baseMidpoints.length; i++) {
const threshold = i % 2 === 0 ? horizontalThreshold : verticalThreshold;
if (
pointDistance(baseMidpoints[i], point) <= threshold &&
!hitElementItself({
@@ -810,8 +807,7 @@ export const getSnapOutlineMidPoint = (
element,
point,
elementsMap,
horizontalThreshold,
verticalThreshold,
maxDistance,
);
if (idx === -1) {
@@ -2469,7 +2469,7 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
"endBinding": {
"elementId": "id1",
"fixedPoint": [
"0.50010",
0,
"0.50010",
],
"mode": "orbit",
@@ -2477,7 +2477,7 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
"fillStyle": "solid",
"frameId": null,
"groupIds": [],
"height": "399.26547",
"height": "439.20000",
"id": "id4",
"index": "a2",
"isDeleted": false,
@@ -2491,8 +2491,8 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
0,
],
[
"488.00000",
"-399.26547",
488,
"-439.20000",
],
],
"roughness": 1,
@@ -2514,9 +2514,9 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
"type": "arrow",
"updated": 1,
"version": 11,
"width": "488.00000",
"width": 488,
"x": 6,
"y": "-4.89900",
"y": "-5.39000",
}
`;
@@ -2640,7 +2640,7 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
"endBinding": {
"elementId": "id1",
"fixedPoint": [
"0.50010",
0,
"0.50010",
],
"mode": "orbit",
@@ -2648,7 +2648,7 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
"fillStyle": "solid",
"frameId": null,
"groupIds": [],
"height": "399.26547",
"height": "439.20000",
"index": "a2",
"isDeleted": false,
"link": null,
@@ -2660,8 +2660,8 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
0,
],
[
"488.00000",
"-399.26547",
488,
"-439.20000",
],
],
"roughness": 1,
@@ -2682,9 +2682,9 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
"strokeWidth": 2,
"type": "arrow",
"version": 11,
"width": "488.00000",
"width": 488,
"x": 6,
"y": "-4.89900",
"y": "-5.39000",
},
"inserted": {
"isDeleted": true,
@@ -168,7 +168,7 @@ exports[`move element > rectangles with binding arrow 6`] = `
"type": "rectangle",
"updated": 1,
"version": 7,
"versionNonce": 735304455,
"versionNonce": 888958951,
"width": 300,
"x": 201,
"y": 2,
@@ -232,8 +232,8 @@ exports[`move element > rectangles with binding arrow 7`] = `
"strokeWidth": 2,
"type": "arrow",
"updated": 1,
"version": 13,
"versionNonce": 271613161,
"version": 12,
"versionNonce": 2066753033,
"width": 89,
"x": 106,
"y": "56.01120",
+1 -1
View File
@@ -5133,7 +5133,7 @@ describe("history", () => {
}),
endBinding: expect.objectContaining({
elementId: rect2.id,
fixedPoint: expect.arrayContaining([0.5001, 0.5001]),
fixedPoint: expect.arrayContaining([0, 0.5001]),
}),
isDeleted: true,
}),
+4 -10
View File
@@ -116,13 +116,10 @@ describe("move element", () => {
expect([rectA.x, rectA.y]).toEqual([0, 0]);
expect([rectB.x, rectB.y]).toEqual([200, 0]);
expect([[arrow.x, arrow.y]]).toCloselyEqualPoints(
[[106, 56.011199999998695]],
0,
);
expect([[arrow.width, arrow.height]]).toCloselyEqualPoints(
[[88, 88.01760000000121]],
[[106.00000000000001, 55.6867741935484]],
0,
);
expect([[arrow.width, arrow.height]]).toCloselyEqualPoints([[88, 88]], 0);
renderInteractiveScene.mockClear();
renderStaticScene.mockClear();
@@ -141,13 +138,10 @@ describe("move element", () => {
expect([rectA.x, rectA.y]).toEqual([0, 0]);
expect([rectB.x, rectB.y]).toEqual([201, 2]);
expect([[arrow.x, arrow.y]]).toCloselyEqualPoints(
[[106, 56.011199999998695]],
0,
);
expect([[arrow.width, arrow.height]]).toCloselyEqualPoints(
[[89, 90.01760000000121]],
[[106, 55.6867741935484]],
0,
);
expect([[arrow.width, arrow.height]]).toCloselyEqualPoints([[89, 90]], 0);
h.elements.forEach((element) => expect(element).toMatchSnapshot());
});