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

View file

@ -2925,28 +2925,6 @@ class App extends React.Component<AppProps, AppState> {
this.setState({ selectedLinearElement: null }); 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); this.store.commit(elementsMap, this.state);
// Do not notify consumers if we're still loading the scene. Among other // 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", "type": "rectangle",
"updated": 1, "updated": 1,
"version": 7, "version": 7,
"versionNonce": 745419401, "versionNonce": 1051383431,
"width": 300, "width": 300,
"x": 201, "x": 201,
"y": 2, "y": 2,
@ -231,7 +231,7 @@ exports[`move element > rectangles with binding arrow 7`] = `
"type": "arrow", "type": "arrow",
"updated": 1, "updated": 1,
"version": 11, "version": 11,
"versionNonce": 1051383431, "versionNonce": 1996028265,
"width": "86.85786", "width": "86.85786",
"x": "107.07107", "x": "107.07107",
"y": "47.07107", "y": "47.07107",