Skip to content

Virtual whiteboard for sketching hand-drawn like diagrams

feat: do not break polygon on point delete inside line editor (#9580)

David Luzarfc3e0620749b
diff --git a/packages/element/src/linearElementEditor.ts b/packages/element/src/linearElementEditor.ts
index ae752eeae2..ca3d60c63c 100644
--- a/packages/element/src/linearElementEditor.ts
+++ b/packages/element/src/linearElementEditor.ts
@@ -1290,24 +1290,19 @@ export class LinearElementEditor {
app.state.editingLinearElement?.lastUncommittedPoint ===
element.points[element.points.length - 1];
+ const nextPoints = element.points.filter((_, idx) => {
+ return !pointIndices.includes(idx);
+ });
+
const isPolygon = isLineElement(element) && element.polygon;
- // break polygon if deleting start/end point
+ // keep polygon intact if deleting start/end point or uncommitted point
if (
isPolygon &&
- // don't disable polygon if cleaning up uncommitted point
- !isUncommittedPoint &&
- (pointIndices.includes(0) ||
+ (isUncommittedPoint ||
+ pointIndices.includes(0) ||
pointIndices.includes(element.points.length - 1))
) {
- app.scene.mutateElement(element, { polygon: false });
- }
-
- const nextPoints = element.points.filter((_, idx) => {
- return !pointIndices.includes(idx);
- });
-
- if (isUncommittedPoint && isLineElement(element) && element.polygon) {
nextPoints[0] = pointFrom(
nextPoints[nextPoints.length - 1][0],
nextPoints[nextPoints.length - 1][1],
diff --git a/packages/excalidraw/renderer/interactiveScene.ts b/packages/excalidraw/renderer/interactiveScene.ts
index ac0cb52690..7d8b474858 100644
--- a/packages/excalidraw/renderer/interactiveScene.ts
+++ b/packages/excalidraw/renderer/interactiveScene.ts
@@ -459,18 +459,27 @@ const renderLinearPointHandles = (
const isOverlappingPoint =
idx > 0 &&
- (idx !== points.length - 1 ||
- appState.editingLinearElement ||
- !_isLineElement ||
- !element.polygon) &&
+ (idx !== points.length - 1 || !_isLineElement || !element.polygon) &&
pointsEqual(
point,
idx === points.length - 1 ? points[0] : points[idx - 1],
2 / appState.zoom.value,
);
- const isSelected =
+ let isSelected =
!!appState.editingLinearElement?.selectedPointsIndices?.includes(idx);
+ // when element is a polygon, highlight the last point as well if first
+ // point is selected since they overlap and the last point tends to be
+ // rendered on top
+ if (
+ _isLineElement &&
+ element.polygon &&
+ !isSelected &&
+ idx === element.points.length - 1 &&
+ !!appState.editingLinearElement?.selectedPointsIndices?.includes(0)
+ ) {
+ isSelected = true;
+ }
renderSingleLinearPoint(
context,