fix: Inside binding grid respect

Signed-off-by: Mark Tolmacs <mark@lazycat.hu>
This commit is contained in:
Mark Tolmacs
2026-03-19 14:55:56 +00:00
parent d7abb6a309
commit de2ad7cd3f
5 changed files with 24 additions and 15 deletions
+5 -4
View File
@@ -1,4 +1,5 @@
import { import {
pointFrom,
pointFromPair, pointFromPair,
type GlobalPoint, type GlobalPoint,
type LocalPoint, type LocalPoint,
@@ -69,12 +70,12 @@ export const getGridPoint = (
x: number, x: number,
y: number, y: number,
gridSize: NullableGridSize, gridSize: NullableGridSize,
): [number, number] => { ): GlobalPoint => {
if (gridSize) { if (gridSize) {
return [ return pointFrom<GlobalPoint>(
Math.round(x / gridSize) * gridSize, Math.round(x / gridSize) * gridSize,
Math.round(y / gridSize) * gridSize, Math.round(y / gridSize) * gridSize,
]; );
} }
return [x, y]; return pointFrom<GlobalPoint>(x, y);
}; };
@@ -244,7 +244,7 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to existing t
"backgroundColor": "transparent", "backgroundColor": "transparent",
"boundElements": [ "boundElements": [
{ {
"id": "id50", "id": "id6",
"type": "arrow", "type": "arrow",
}, },
], ],
@@ -290,7 +290,7 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to existing t
"backgroundColor": "transparent", "backgroundColor": "transparent",
"boundElements": [ "boundElements": [
{ {
"id": "id50", "id": "id6",
"type": "arrow", "type": "arrow",
}, },
], ],
@@ -335,7 +335,7 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to existing t
"backgroundColor": "transparent", "backgroundColor": "transparent",
"boundElements": [ "boundElements": [
{ {
"id": "id51", "id": "id7",
"type": "text", "type": "text",
}, },
], ],
@@ -401,7 +401,7 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to existing t
"autoResize": true, "autoResize": true,
"backgroundColor": "transparent", "backgroundColor": "transparent",
"boundElements": null, "boundElements": null,
"containerId": "id50", "containerId": "id6",
"customData": undefined, "customData": undefined,
"fillStyle": "solid", "fillStyle": "solid",
"fontFamily": 5, "fontFamily": 5,
@@ -1316,7 +1316,7 @@ exports[`Test Transform > should transform the elements correctly when linear el
"backgroundColor": "transparent", "backgroundColor": "transparent",
"boundElements": [ "boundElements": [
{ {
"id": "id56", "id": "id11",
"type": "text", "type": "text",
}, },
{ {
@@ -1359,7 +1359,7 @@ exports[`Test Transform > should transform the elements correctly when linear el
"backgroundColor": "transparent", "backgroundColor": "transparent",
"boundElements": [ "boundElements": [
{ {
"id": "id57", "id": "id12",
"type": "text", "type": "text",
}, },
], ],
@@ -1398,7 +1398,7 @@ exports[`Test Transform > should transform the elements correctly when linear el
"backgroundColor": "transparent", "backgroundColor": "transparent",
"boundElements": [ "boundElements": [
{ {
"id": "id58", "id": "id13",
"type": "text", "type": "text",
}, },
{ {
@@ -1441,7 +1441,7 @@ exports[`Test Transform > should transform the elements correctly when linear el
"backgroundColor": "transparent", "backgroundColor": "transparent",
"boundElements": [ "boundElements": [
{ {
"id": "id59", "id": "id14",
"type": "text", "type": "text",
}, },
{ {
@@ -1488,7 +1488,7 @@ exports[`Test Transform > should transform the elements correctly when linear el
"backgroundColor": "transparent", "backgroundColor": "transparent",
"boundElements": [ "boundElements": [
{ {
"id": "id60", "id": "id15",
"type": "text", "type": "text",
}, },
], ],
@@ -1556,7 +1556,7 @@ exports[`Test Transform > should transform the elements correctly when linear el
"backgroundColor": "transparent", "backgroundColor": "transparent",
"boundElements": [ "boundElements": [
{ {
"id": "id61", "id": "id16",
"type": "text", "type": "text",
}, },
], ],
+7 -1
View File
@@ -155,6 +155,7 @@ export const bindOrUnbindBindingElement = (
altKey?: boolean; altKey?: boolean;
angleLocked?: boolean; angleLocked?: boolean;
initialBinding?: boolean; initialBinding?: boolean;
gridSize?: NullableGridSize;
}, },
) => { ) => {
const { start, end } = getBindingStrategyForDraggingBindingElementEndpoints( const { start, end } = getBindingStrategyForDraggingBindingElementEndpoints(
@@ -594,6 +595,7 @@ export const getBindingStrategyForDraggingBindingElementEndpoints = (
finalize?: boolean; finalize?: boolean;
initialBinding?: boolean; initialBinding?: boolean;
zoom?: AppState["zoom"]; zoom?: AppState["zoom"];
gridSize?: NullableGridSize;
}, },
): { start: BindingStrategy; end: BindingStrategy } => { ): { start: BindingStrategy; end: BindingStrategy } => {
if (getFeatureFlag("COMPLEX_BINDINGS")) { if (getFeatureFlag("COMPLEX_BINDINGS")) {
@@ -752,7 +754,11 @@ const getBindingStrategyForDraggingBindingElementEndpoints_simple = (
? globalPoint ? globalPoint
: // 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! ? getGridPoint(
appState.selectedLinearElement!.initialState.origin![0],
appState.selectedLinearElement!.initialState.origin![1],
opts.gridSize as NullableGridSize,
)
: LinearElementEditor.getPointAtIndexGlobalCoordinates( : LinearElementEditor.getPointAtIndexGlobalCoordinates(
arrow, arrow,
0, 0,
@@ -2172,6 +2172,7 @@ const pointDraggingUpdates = (
newArrow: !!app.state.newElement, newArrow: !!app.state.newElement,
angleLocked, angleLocked,
altKey, altKey,
gridSize: app.getEffectiveGridSize(),
}, },
); );
@@ -126,6 +126,7 @@ export const actionFinalize = register<FormData>({
newArrow, newArrow,
altKey: event.altKey, altKey: event.altKey,
angleLocked, angleLocked,
gridSize: app.getEffectiveGridSize(),
}, },
); );
} else if (isLineElement(element)) { } else if (isLineElement(element)) {