From b583efd01ea191e275e08c38973524bf29a29f20 Mon Sep 17 00:00:00 2001 From: ivmartel Date: Wed, 17 Jul 2024 16:55:44 +0200 Subject: [PATCH] Add reference points to update --- src/tools/drawShapeEditor.js | 25 +++++++++++++++++-------- src/tools/drawShapeHandler.js | 26 ++++++++++++++++++-------- 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/src/tools/drawShapeEditor.js b/src/tools/drawShapeEditor.js index 0e8b006bb7..2a237a3540 100644 --- a/src/tools/drawShapeEditor.js +++ b/src/tools/drawShapeEditor.js @@ -287,14 +287,17 @@ export class DrawShapeEditor { * @param {Konva.Ellipse} anchor The anchor to set on. */ #setAnchorOn(anchor) { - let originaMathShape; + let originalProps; // drag start listener anchor.on('dragstart.edit', (event) => { // prevent bubbling upwards event.cancelBubble = true; - // store original math shape - originaMathShape = this.#annotation.mathShape; + // store original properties + originalProps = { + mathShape: this.#annotation.mathShape, + referencePoints: this.#annotation.referencePoints + }; }); // drag move listener anchor.on('dragmove.edit', (event) => { @@ -327,11 +330,14 @@ export class DrawShapeEditor { // drag end listener anchor.on('dragend.edit', (event) => { // update annotation command - const newMathShape = this.#annotation.mathShape; + const newProps = { + mathShape: this.#annotation.mathShape, + referencePoints: this.#annotation.referencePoints + }; const command = new UpdateAnnotationCommand( this.#annotation, - {mathShape: originaMathShape}, - {mathShape: newMathShape}, + originalProps, + newProps, this.#drawLayer.getDrawController() ); // add command to undo stack @@ -341,8 +347,11 @@ export class DrawShapeEditor { type: 'annotationupdate', data: this.#annotation }); - // update original shape - originaMathShape = newMathShape; + // update original properties + originalProps = { + mathShape: newProps.mathShape, + referencePoints: newProps.referencePoints + } // prevent bubbling upwards event.cancelBubble = true; diff --git a/src/tools/drawShapeHandler.js b/src/tools/drawShapeHandler.js index 352b3bec0f..a7dc1a4f18 100644 --- a/src/tools/drawShapeHandler.js +++ b/src/tools/drawShapeHandler.js @@ -268,7 +268,7 @@ export class DrawShapeHandler { // cache vars let dragStartPos; let previousPos; - let originaMathShape; + let originalProps; let colour; // shape listeners ------------------------------------------ @@ -286,8 +286,11 @@ export class DrawShapeHandler { x: event.target.x(), y: event.target.y() }; - // store the original math shape - originaMathShape = annotation.mathShape; + // store original properties + originalProps = { + mathShape: annotation.mathShape, + referencePoints: annotation.referencePoints + }; // display trash this.#trash.activate(drawLayer); @@ -369,7 +372,8 @@ export class DrawShapeHandler { this.#shapeEditor.reset(); this.#trash.changeGroupChildrenColour(shapeGroup, colour); // reset math shape (for undo) - annotation.mathShape = originaMathShape; + annotation.mathShape = originalProps.mathShape; + annotation.referencePoints = originalProps.referencePoints; // create remove annotation command const command = new RemoveAnnotationCommand( @@ -390,11 +394,14 @@ export class DrawShapeHandler { }; if (translation.x !== 0 || translation.y !== 0) { // update annotation command - const newMathShape = annotation.mathShape; + const newProps = { + mathShape: annotation.mathShape, + referencePoints: annotation.referencePoints + }; const command = new UpdateAnnotationCommand( annotation, - {mathShape: originaMathShape}, - {mathShape: newMathShape}, + originalProps, + newProps, drawLayer.getDrawController() ); // add command to undo stack @@ -405,7 +412,10 @@ export class DrawShapeHandler { data: annotation }); // update original shape - originaMathShape = newMathShape; + originalProps = { + mathShape: newProps.mathShape, + referencePoints: newProps.referencePoints + }; } // reset anchors this.#shapeEditor.setAnchorsActive(true);