From 8e01c1890cb5588eb59061c97432c625d24b8743 Mon Sep 17 00:00:00 2001 From: agriyadev5 Date: Tue, 6 Jul 2021 17:56:28 +0530 Subject: [PATCH] #543 if you move the group and try to undo the move, the text does not undo correctly issue fixed --- src/svgcanvas/undo.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/svgcanvas/undo.js b/src/svgcanvas/undo.js index d0c0ec5a..d61e7809 100644 --- a/src/svgcanvas/undo.js +++ b/src/svgcanvas/undo.js @@ -98,6 +98,24 @@ export const getUndoManager = function () { // // Ok to replace above with this? `sib.before(elem);` // } // } + if (cmd.elem.tagName === 'text'){ + const [ dx, dy ] = [ cmd.newValues.x - cmd.oldValues.x, + cmd.newValues.y - cmd.oldValues.y ]; + + const tspans = cmd.elem.children; + + for (let i = 0; i < tspans.length; i++){ + let x = +tspans[i].getAttribute('x'); + let y = +tspans[i].getAttribute('y'); + + const unapply = (eventType === EventTypes.AFTER_UNAPPLY); + x = unapply? x - dx: x + dx; + y = unapply? y - dy: y + dy; + + tspans[i].setAttribute('x', x); + tspans[i].setAttribute('y', y); + } + } } } }