This commit is contained in:
dwelle 2025-05-14 20:46:53 +02:00
parent 7ce0615411
commit d3ee66b7cc
4 changed files with 13 additions and 11 deletions

View File

@ -477,4 +477,9 @@ export enum UserIdleState {
IDLE = "idle", IDLE = "idle",
} }
export const MIN_LOOP_LOCK_DISTANCE = 20; /**
* distance at which we merge points instead of adding a new merge-point
* when converting a line to a polygon (merge currently means overlaping
* the start and end points)
*/
export const LINE_POLYGON_POINT_MERGE_DISTANCE = 20;

View File

@ -1390,7 +1390,7 @@ export class LinearElementEditor {
) { ) {
const { points } = element; const { points } = element;
// Handle loop lock behavior // if polygon, move start and end points together
if (isLineElement(element) && element.polygon) { if (isLineElement(element) && element.polygon) {
const firstPointUpdate = pointUpdates.get(0); const firstPointUpdate = pointUpdates.get(0);
const lastPointUpdate = pointUpdates.get(points.length - 1); const lastPointUpdate = pointUpdates.get(points.length - 1);

View File

@ -5,7 +5,7 @@ import {
ROUNDNESS, ROUNDNESS,
invariant, invariant,
elementCenterPoint, elementCenterPoint,
MIN_LOOP_LOCK_DISTANCE, LINE_POLYGON_POINT_MERGE_DISTANCE,
} from "@excalidraw/common"; } from "@excalidraw/common";
import { import {
isPoint, isPoint,
@ -414,7 +414,7 @@ export const toggleLinePolygonState = (
firstPoint[1] - lastPoint[1], firstPoint[1] - lastPoint[1],
); );
if (distance > MIN_LOOP_LOCK_DISTANCE) { if (distance > LINE_POLYGON_POINT_MERGE_DISTANCE) {
updatedPoints.push(pointFrom(firstPoint[0], firstPoint[1])); updatedPoints.push(pointFrom(firstPoint[0], firstPoint[1]));
} else { } else {
updatedPoints[updatedPoints.length - 1] = pointFrom( updatedPoints[updatedPoints.length - 1] = pointFrom(

View File

@ -104,14 +104,11 @@ export const actionTogglePolygon = register({
selectedElementIds: appState.selectedElementIds, selectedElementIds: appState.selectedElementIds,
}); });
// Check if all selected elements are locked const allPolygons = !selectedElements.some(
const allLocked = (element) => !isLineElement(element) || !element.polygon,
selectedElements.length > 0 && );
selectedElements.every(
(element) => isLineElement(element) && element.polygon,
);
return allLocked return allPolygons
? "labels.polygon.breakPolygon" ? "labels.polygon.breakPolygon"
: "labels.polygon.convertToPolygon"; : "labels.polygon.convertToPolygon";
}, },