diff --git a/packages/common/src/constants.ts b/packages/common/src/constants.ts index 3184e8f67..88d9c8f11 100644 --- a/packages/common/src/constants.ts +++ b/packages/common/src/constants.ts @@ -477,4 +477,9 @@ export enum UserIdleState { 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; diff --git a/packages/element/src/linearElementEditor.ts b/packages/element/src/linearElementEditor.ts index f14ba45b3..397f042f0 100644 --- a/packages/element/src/linearElementEditor.ts +++ b/packages/element/src/linearElementEditor.ts @@ -1390,7 +1390,7 @@ export class LinearElementEditor { ) { const { points } = element; - // Handle loop lock behavior + // if polygon, move start and end points together if (isLineElement(element) && element.polygon) { const firstPointUpdate = pointUpdates.get(0); const lastPointUpdate = pointUpdates.get(points.length - 1); diff --git a/packages/element/src/shapes.ts b/packages/element/src/shapes.ts index d64a0ca37..cc6481908 100644 --- a/packages/element/src/shapes.ts +++ b/packages/element/src/shapes.ts @@ -5,7 +5,7 @@ import { ROUNDNESS, invariant, elementCenterPoint, - MIN_LOOP_LOCK_DISTANCE, + LINE_POLYGON_POINT_MERGE_DISTANCE, } from "@excalidraw/common"; import { isPoint, @@ -414,7 +414,7 @@ export const toggleLinePolygonState = ( firstPoint[1] - lastPoint[1], ); - if (distance > MIN_LOOP_LOCK_DISTANCE) { + if (distance > LINE_POLYGON_POINT_MERGE_DISTANCE) { updatedPoints.push(pointFrom(firstPoint[0], firstPoint[1])); } else { updatedPoints[updatedPoints.length - 1] = pointFrom( diff --git a/packages/excalidraw/actions/actionLinearEditor.tsx b/packages/excalidraw/actions/actionLinearEditor.tsx index 1c9e460bc..32eba3339 100644 --- a/packages/excalidraw/actions/actionLinearEditor.tsx +++ b/packages/excalidraw/actions/actionLinearEditor.tsx @@ -104,14 +104,11 @@ export const actionTogglePolygon = register({ selectedElementIds: appState.selectedElementIds, }); - // Check if all selected elements are locked - const allLocked = - selectedElements.length > 0 && - selectedElements.every( - (element) => isLineElement(element) && element.polygon, - ); + const allPolygons = !selectedElements.some( + (element) => !isLineElement(element) || !element.polygon, + ); - return allLocked + return allPolygons ? "labels.polygon.breakPolygon" : "labels.polygon.convertToPolygon"; },