update indices when inserting/removing points
This commit is contained in:
parent
bc5436592e
commit
89218ba596
@ -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);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user