From 79beed3f5c75fb9faa92f420468ff5679a1bad60 Mon Sep 17 00:00:00 2001 From: Ryan Di Date: Tue, 28 Apr 2026 16:16:10 +1000 Subject: [PATCH] refactor(snapping): clarify linear point reference options --- packages/element/src/linearElementEditor.ts | 5 +++-- packages/element/src/snapping.ts | 24 ++++++++++----------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/packages/element/src/linearElementEditor.ts b/packages/element/src/linearElementEditor.ts index 92fef508cc..7045736e2f 100644 --- a/packages/element/src/linearElementEditor.ts +++ b/packages/element/src/linearElementEditor.ts @@ -1913,8 +1913,9 @@ export class LinearElementEditor { event, elementsMap, { - includeSelfPoints: true, - selectedPointsIndices, + selfReferencePoints: { + excludedPointIndices: selectedPointsIndices, + }, }, ); diff --git a/packages/element/src/snapping.ts b/packages/element/src/snapping.ts index 09610c379e..c734519527 100644 --- a/packages/element/src/snapping.ts +++ b/packages/element/src/snapping.ts @@ -654,19 +654,20 @@ export const getReferenceSnapPoints = ( .flatMap((elementGroup) => getElementsCorners(elementGroup, elementsMap)); }; +type LinearElementPointReferencePointsOptions = { + selfReferencePoints?: { + excludedPointIndices?: readonly number[]; + }; +}; + export const getReferenceSnapPointsForLinearElementPoint = ( elements: readonly NonDeletedExcalidrawElement[], editingElement: ExcalidrawLinearElement, editingPointIndex: number, appState: AppState, elementsMap: ElementsMap, - options: { - includeSelfPoints?: boolean; - selectedPointsIndices?: readonly number[]; - } = {}, + options: LinearElementPointReferencePointsOptions = {}, ) => { - const { includeSelfPoints = false } = options; - // Get all reference elements (excluding the one being edited) const referenceElements = getReferenceElements( elements, @@ -691,12 +692,14 @@ export const getReferenceSnapPointsForLinearElementPoint = ( } // Include other points from the same linear element when creating new points or in editing mode - if (includeSelfPoints) { + if (options.selfReferencePoints) { + const excludedPointIndices = + options.selfReferencePoints.excludedPointIndices ?? [editingPointIndex]; const elementPoints = LinearElementEditor.getPointsGlobalCoordinates( editingElement as NonDeleted, elementsMap, { - excludePointsIndices: options.selectedPointsIndices, + excludePointsIndices: excludedPointIndices, }, ); allSnapPoints.push(...elementPoints); @@ -713,10 +716,7 @@ export const snapLinearElementPoint = ( app: AppClassProperties, event: KeyboardModifiersObject, elementsMap: ElementsMap, - options: { - includeSelfPoints?: boolean; - selectedPointsIndices?: readonly number[]; - } = {}, + options: LinearElementPointReferencePointsOptions = {}, ) => { if ( !isSnappingEnabled({ app, event, selectedElements: [editingElement] }) ||