From 89218ba5964ba42a1bc66babd24fb9499e1fe1c9 Mon Sep 17 00:00:00 2001 From: Preet <833927+pshihn@users.noreply.github.com> Date: Sun, 22 Oct 2023 17:39:51 -0700 Subject: [PATCH] update indices when inserting/removing points --- src/element/linearElementEditor.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/element/linearElementEditor.ts b/src/element/linearElementEditor.ts index a8e371f8f..67ffc737d 100644 --- a/src/element/linearElementEditor.ts +++ b/src/element/linearElementEditor.ts @@ -1065,7 +1065,20 @@ export class LinearElementEditor { return acc; }, []); - LinearElementEditor._updatePoints(element, nextPoints, offsetX, offsetY); + const splits: number[] = []; + (element.segmentSplitIndices || []).forEach((index) => { + if (!pointIndices.includes(index)) { + let shift = 0; + for (const pointIndex of pointIndices) { + if (index > pointIndex) { + shift++; + } + } + splits.push(index - shift); + } + }); + + LinearElementEditor._updatePoints(element, nextPoints, offsetX, offsetY, { segmentSplitIndices: splits }); } static addPoints( @@ -1204,9 +1217,11 @@ export class LinearElementEditor { midpoint, ...element.points.slice(segmentMidpoint.index!), ]; + const splits = (element.segmentSplitIndices || []).map((index) => (index >= segmentMidpoint.index!) ? (index + 1) : index); mutateElement(element, { points, + segmentSplitIndices: splits, }); ret.pointerDownState = { @@ -1226,7 +1241,7 @@ export class LinearElementEditor { nextPoints: readonly Point[], offsetX: number, offsetY: number, - otherUpdates?: { startBinding?: PointBinding; endBinding?: PointBinding }, + otherUpdates?: { startBinding?: PointBinding; endBinding?: PointBinding, segmentSplitIndices?: number[] }, ) { const nextCoords = getElementPointsCoords(element, nextPoints); const prevCoords = getElementPointsCoords(element, element.points);