Additional fixes

Signed-off-by: Mark Tolmacs <mark@lazycat.hu>
This commit is contained in:
Mark Tolmacs 2025-05-01 09:07:50 +02:00
parent 9b643abcee
commit 4ffe7fd991
No known key found for this signature in database
3 changed files with 33 additions and 54 deletions

View file

@ -41,7 +41,7 @@ export const actionFinalize = register({
const { interactiveCanvas, focusContainer, scene } = app;
const elementsMap = scene.getNonDeletedElementsMap();
console.log("actionFinalize");
if (data?.event && appState.selectedLinearElement) {
const linearElementEditor = LinearElementEditor.handlePointerUp(
data.event,
@ -162,37 +162,38 @@ export const actionFinalize = register({
newElements = newElements.filter((el) => el.id !== element!.id);
}
// If the multi point line closes the loop,
// set the last point to first point.
// This ensures that loop remains closed at different scales.
const isLoop = isPathALoop(element.points, appState.zoom.value);
if (element.type === "line" || element.type === "freedraw") {
if (isLoop) {
const linePoints = element.points;
const firstPoint = linePoints[0];
scene.mutateElement(element, {
points: linePoints.map((p, index) =>
index === linePoints.length - 1
? pointFrom(firstPoint[0], firstPoint[1])
: p,
),
});
if (isLinearElement(element) || element.type === "freedraw") {
// If the multi point line closes the loop,
// set the last point to first point.
// This ensures that loop remains closed at different scales.
const isLoop = isPathALoop(element.points, appState.zoom.value);
if (element.type === "line" || element.type === "freedraw") {
if (isLoop) {
const linePoints = element.points;
const firstPoint = linePoints[0];
scene.mutateElement(element, {
points: linePoints.map((p, index) =>
index === linePoints.length - 1
? pointFrom(firstPoint[0], firstPoint[1])
: p,
),
});
}
}
}
if (
isBindingElement(element) &&
!isLoop &&
element.points.length > 1 &&
!appState.selectedElementIds[element.id] &&
isBindingEnabled(appState)
) {
const [x, y] = LinearElementEditor.getPointAtIndexGlobalCoordinates(
element,
-1,
arrayToMap(elements),
);
maybeBindLinearElement(element, appState, { x, y }, scene);
if (
isBindingElement(element) &&
!isLoop &&
element.points.length > 1 &&
isBindingEnabled(appState)
) {
const [x, y] = LinearElementEditor.getPointAtIndexGlobalCoordinates(
element,
-1,
arrayToMap(elements),
);
maybeBindLinearElement(element, appState, { x, y }, scene);
}
}
}

View file

@ -2925,28 +2925,6 @@ class App extends React.Component<AppProps, AppState> {
this.setState({ selectedLinearElement: null });
}
const { multiElement } = prevState;
if (
prevState.activeTool !== this.state.activeTool &&
multiElement != null &&
isBindingEnabled(this.state) &&
isBindingElement(multiElement, false)
) {
this.actionManager.executeAction(actionFinalize);
// maybeBindLinearElement(
// multiElement,
// this.state,
// tupleToCoors(
// LinearElementEditor.getPointAtIndexGlobalCoordinates(
// multiElement,
// -1,
// nonDeletedElementsMap,
// ),
// ),
// this.scene,
// );
}
this.store.commit(elementsMap, this.state);
// Do not notify consumers if we're still loading the scene. Among other

View file

@ -173,7 +173,7 @@ exports[`move element > rectangles with binding arrow 6`] = `
"type": "rectangle",
"updated": 1,
"version": 7,
"versionNonce": 745419401,
"versionNonce": 1051383431,
"width": 300,
"x": 201,
"y": 2,
@ -231,7 +231,7 @@ exports[`move element > rectangles with binding arrow 7`] = `
"type": "arrow",
"updated": 1,
"version": 11,
"versionNonce": 1051383431,
"versionNonce": 1996028265,
"width": "86.85786",
"x": "107.07107",
"y": "47.07107",