update indices when inserting/removing points

This commit is contained in:
Preet 2023-10-22 17:39:51 -07:00
parent bc5436592e
commit 89218ba596

View File

@ -1065,7 +1065,20 @@ export class LinearElementEditor {
return acc; 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( static addPoints(
@ -1204,9 +1217,11 @@ export class LinearElementEditor {
midpoint, midpoint,
...element.points.slice(segmentMidpoint.index!), ...element.points.slice(segmentMidpoint.index!),
]; ];
const splits = (element.segmentSplitIndices || []).map((index) => (index >= segmentMidpoint.index!) ? (index + 1) : index);
mutateElement(element, { mutateElement(element, {
points, points,
segmentSplitIndices: splits,
}); });
ret.pointerDownState = { ret.pointerDownState = {
@ -1226,7 +1241,7 @@ export class LinearElementEditor {
nextPoints: readonly Point[], nextPoints: readonly Point[],
offsetX: number, offsetX: number,
offsetY: number, offsetY: number,
otherUpdates?: { startBinding?: PointBinding; endBinding?: PointBinding }, otherUpdates?: { startBinding?: PointBinding; endBinding?: PointBinding, segmentSplitIndices?: number[] },
) { ) {
const nextCoords = getElementPointsCoords(element, nextPoints); const nextCoords = getElementPointsCoords(element, nextPoints);
const prevCoords = getElementPointsCoords(element, element.points); const prevCoords = getElementPointsCoords(element, element.points);