aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/InkStrokeProperties.ts
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2021-09-29 01:38:15 -0400
committerbobzel <zzzman@gmail.com>2021-09-29 01:38:15 -0400
commitaed57a2d6435007676409aeba562fc11d0c4a44d (patch)
treeb14f348cdb1dd78c6d044c0d40ee767888eab2bb /src/client/views/InkStrokeProperties.ts
parentfaaa10bfeaf9c4a33a75884c3cf93eb3138464d1 (diff)
a number of undo/redo fixes for ink (snapping to tangent, add points, dragging tangents). also tried to make storage of undo events more efficient when dragging ink controls (avoid saving hundreds of copies of the InkField)
Diffstat (limited to 'src/client/views/InkStrokeProperties.ts')
-rw-r--r--src/client/views/InkStrokeProperties.ts19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/client/views/InkStrokeProperties.ts b/src/client/views/InkStrokeProperties.ts
index 6a503cc91..3770eb7c1 100644
--- a/src/client/views/InkStrokeProperties.ts
+++ b/src/client/views/InkStrokeProperties.ts
@@ -214,14 +214,16 @@ export class InkStrokeProperties {
*/
snapHandleTangent = (controlIndex: number, handleIndexA: number, handleIndexB: number) => {
this.applyFunction((doc: Doc, ink: InkData) => {
- const brokenIndices = Cast(doc.brokenInkIndices, listSpec("number"));
- if (brokenIndices) {
- doc.brokenInkIndices = new List<number>(brokenIndices.filter(brokenIndex => brokenIndex !== controlIndex));
+ const brokenIndices = Cast(doc.brokenInkIndices, listSpec("number"), []);
+ const ind = brokenIndices.findIndex(value => value === controlIndex);
+ if (ind !== -1) {
+ brokenIndices.splice(ind, 1);
const [controlPoint, handleA, handleB] = [ink[controlIndex], ink[handleIndexA], ink[handleIndexB]];
const oppositeHandleA = this.rotatePoint(handleA, controlPoint, Math.PI);
const angleDifference = this.angleChange(handleB, oppositeHandleA, controlPoint);
- ink[handleIndexB] = this.rotatePoint(handleB, controlPoint, angleDifference);
- return ink;
+ const inkCopy = ink.slice();
+ inkCopy[handleIndexB] = this.rotatePoint(handleB, controlPoint, angleDifference);
+ return inkCopy;
}
});
}
@@ -277,13 +279,14 @@ export class InkStrokeProperties {
const oppositeHandlePoint = ink[oppositeHandleIndex];
const controlPoint = ink[controlIndex];
const newHandlePoint = { X: ink[handleIndex].X - deltaX / xScale, Y: ink[handleIndex].Y - deltaY / yScale };
- ink[handleIndex] = newHandlePoint;
+ const inkCopy = ink.slice();
+ inkCopy[handleIndex] = newHandlePoint;
const brokenIndices = Cast(doc.brokenInkIndices, listSpec("number"));
// Rotate opposite handle if user hasn't held 'Alt' key or not first/final control (which have only 1 handle).
if ((!brokenIndices || !brokenIndices?.includes(controlIndex)) && (closed || (handleIndex !== 1 && handleIndex !== ink.length - 2))) {
const angle = this.angleChange(oldHandlePoint, newHandlePoint, controlPoint);
- ink[oppositeHandleIndex] = this.rotatePoint(oppositeHandlePoint, controlPoint, angle);
+ inkCopy[oppositeHandleIndex] = this.rotatePoint(oppositeHandlePoint, controlPoint, angle);
}
- return ink;
+ return inkCopy;
})
} \ No newline at end of file