diff --git a/src/data/restore.ts b/src/data/restore.ts index e951dbf5e..26a9b331c 100644 --- a/src/data/restore.ts +++ b/src/data/restore.ts @@ -285,6 +285,7 @@ const restoreElement = ( points, x, y, + segmentSplitIndices: [], }); } diff --git a/src/element/linearElementEditor.ts b/src/element/linearElementEditor.ts index adc5aafc4..bdb9a0a73 100644 --- a/src/element/linearElementEditor.ts +++ b/src/element/linearElementEditor.ts @@ -1472,6 +1472,28 @@ export class LinearElementEditor { return coords; }; + + static toggleSegmentSplitAtIndex( + element: NonDeleted, + appState: AppState, + index: number, + ) { + let found = false; + const splitIndices = (element.segmentSplitIndices || []).filter((idx) => { + if (idx === index) { + found = true; + return false; + } + return true; + }); + if (!found) { + splitIndices.push(index); + } + + mutateElement(element, { + segmentSplitIndices: splitIndices, + }); + } } const normalizeSelectedPoints = ( diff --git a/src/element/newElement.ts b/src/element/newElement.ts index bbc98030c..d618a5ac5 100644 --- a/src/element/newElement.ts +++ b/src/element/newElement.ts @@ -374,6 +374,7 @@ export const newLinearElement = ( endBinding: null, startArrowhead: opts.startArrowhead || null, endArrowhead: opts.endArrowhead || null, + segmentSplitIndices: [], }; }; diff --git a/src/element/types.ts b/src/element/types.ts index e8d71cae5..ffa1073bb 100644 --- a/src/element/types.ts +++ b/src/element/types.ts @@ -195,6 +195,7 @@ export type ExcalidrawLinearElement = _ExcalidrawElementBase & Readonly<{ type: "line" | "arrow"; points: readonly Point[]; + segmentSplitIndices: readonly number[] | null; lastCommittedPoint: Point | null; startBinding: PointBinding | null; endBinding: PointBinding | null;