Do not snap linear elements

Signed-off-by: Mark Tolmacs <mark@lazycat.hu>
This commit is contained in:
Mark Tolmacs 2025-04-04 19:05:13 +02:00
parent 06b3750a2f
commit 6b9fa5bcc5
4 changed files with 85 additions and 63 deletions

View file

@ -525,6 +525,8 @@ export const bindLinearElement = (
};
}
const points = Array.from(linearElement.points);
if (isArrowElement(linearElement)) {
points[edgePointIndex] = toLocalPoint(
bindPointToSnapToElementOutline(
linearElement,
@ -534,6 +536,7 @@ export const bindLinearElement = (
),
linearElement,
);
}
mutateElement(linearElement, {
points,

View file

@ -57,6 +57,7 @@ import { headingIsHorizontal, vectorToHeading } from "./heading";
import { bumpVersion, mutateElement } from "./mutateElement";
import { getBoundTextElement, handleBindTextResize } from "./textElement";
import {
isArrowElement,
isBindingElement,
isElbowArrow,
isFixedPointBinding,
@ -371,13 +372,16 @@ export class LinearElementEditor {
app.scene,
app.state.zoom,
);
newPointPosition = LinearElementEditor.createPointAt(
element,
elementsMap,
!isArrowElement(element) ||
avoidancePoint[0] === newGlobalPointPosition[0]
? newGlobalPointPosition[0] -
linearElementEditor.pointerOffset.x
: avoidancePoint[0],
!isArrowElement(element) ||
avoidancePoint[1] === newGlobalPointPosition[1]
? newGlobalPointPosition[1] -
linearElementEditor.pointerOffset.y

View file

@ -5991,7 +5991,8 @@ class App extends React.Component<AppProps, AppState> {
{
points: [
...points.slice(0, -1),
toLocalPoint(
isArrowElement(multiElement)
? toLocalPoint(
getOutlineAvoidingPoint(
multiElement,
pointFrom<GlobalPoint>(scenePointerX, scenePointerY),
@ -6004,6 +6005,10 @@ class App extends React.Component<AppProps, AppState> {
),
),
multiElement,
)
: pointFrom<LocalPoint>(
lastCommittedX + dxFromLastCommitted,
lastCommittedY + dyFromLastCommitted,
),
],
},
@ -8711,10 +8716,14 @@ class App extends React.Component<AppProps, AppState> {
{
points: [
...points,
toLocalPoint(
isArrowElement(newElement)
? toLocalPoint(
getOutlineAvoidingPoint(
newElement,
pointFrom<GlobalPoint>(pointerCoords.x, pointerCoords.y),
pointFrom<GlobalPoint>(
pointerCoords.x,
pointerCoords.y,
),
newElement.points.length - 1,
this.scene,
this.state.zoom,
@ -8724,7 +8733,8 @@ class App extends React.Component<AppProps, AppState> {
),
),
newElement,
),
)
: pointFrom<LocalPoint>(dx, dy),
],
},
false,
@ -8738,10 +8748,14 @@ class App extends React.Component<AppProps, AppState> {
{
points: [
...points.slice(0, -1),
toLocalPoint(
isArrowElement(newElement)
? toLocalPoint(
getOutlineAvoidingPoint(
newElement,
pointFrom<GlobalPoint>(pointerCoords.x, pointerCoords.y),
pointFrom<GlobalPoint>(
pointerCoords.x,
pointerCoords.y,
),
newElement.points.length - 1,
this.scene,
this.state.zoom,
@ -8751,7 +8765,8 @@ class App extends React.Component<AppProps, AppState> {
),
),
newElement,
),
)
: pointFrom<LocalPoint>(dx, dy),
],
},
false,

View file

@ -427,7 +427,7 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to shapes whe
"backgroundColor": "transparent",
"boundElements": [
{
"id": "id1",
"id": "id40",
"type": "text",
},
],
@ -435,7 +435,7 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to shapes whe
"elbowed": false,
"endArrowhead": "arrow",
"endBinding": {
"elementId": "id3",
"elementId": "id42",
"focus": -0,
"gap": 5,
},
@ -465,7 +465,7 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to shapes whe
"seed": Any<Number>,
"startArrowhead": null,
"startBinding": {
"elementId": "id2",
"elementId": "id41",
"focus": 0,
"gap": 5,
},
@ -488,7 +488,7 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to shapes whe
"autoResize": true,
"backgroundColor": "transparent",
"boundElements": null,
"containerId": "id0",
"containerId": "id39",
"customData": undefined,
"fillStyle": "solid",
"fontFamily": 5,
@ -529,7 +529,7 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to shapes whe
"backgroundColor": "transparent",
"boundElements": [
{
"id": "id0",
"id": "id39",
"type": "arrow",
},
],
@ -566,7 +566,7 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to shapes whe
"backgroundColor": "transparent",
"boundElements": [
{
"id": "id0",
"id": "id39",
"type": "arrow",
},
],
@ -603,7 +603,7 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to text when
"backgroundColor": "transparent",
"boundElements": [
{
"id": "id1",
"id": "id44",
"type": "text",
},
],
@ -611,7 +611,7 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to text when
"elbowed": false,
"endArrowhead": "arrow",
"endBinding": {
"elementId": "id3",
"elementId": "id46",
"focus": -0,
"gap": 5,
},
@ -641,7 +641,7 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to text when
"seed": Any<Number>,
"startArrowhead": null,
"startBinding": {
"elementId": "id2",
"elementId": "id45",
"focus": 0,
"gap": 5,
},
@ -664,7 +664,7 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to text when
"autoResize": true,
"backgroundColor": "transparent",
"boundElements": null,
"containerId": "id0",
"containerId": "id43",
"customData": undefined,
"fillStyle": "solid",
"fontFamily": 5,
@ -706,7 +706,7 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to text when
"backgroundColor": "transparent",
"boundElements": [
{
"id": "id0",
"id": "id43",
"type": "arrow",
},
],
@ -752,7 +752,7 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to text when
"backgroundColor": "transparent",
"boundElements": [
{
"id": "id0",
"id": "id43",
"type": "arrow",
},
],