From 7704bc436ce464e07c815e24292871afe4d7c984 Mon Sep 17 00:00:00 2001 From: km384 <97592792+km384@users.noreply.github.com> Date: Wed, 12 Jan 2022 18:17:56 +0530 Subject: [PATCH] Fix undo on converting rectangle to path creating an exception (#703) --- cypress/integration/ui/issues/issue-699.js | 29 ++++++++++++++++++++++ src/svgcanvas/utilities.js | 6 ++--- 2 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 cypress/integration/ui/issues/issue-699.js diff --git a/cypress/integration/ui/issues/issue-699.js b/cypress/integration/ui/issues/issue-699.js new file mode 100644 index 00000000..98dd8fa8 --- /dev/null +++ b/cypress/integration/ui/issues/issue-699.js @@ -0,0 +1,29 @@ +import { + visitAndApproveStorage +} from '../../../support/ui-test-helper.js' + +// See https://github.com/SVG-Edit/svgedit/issues/699 +describe('Fix issue 699', function () { + beforeEach(() => { + visitAndApproveStorage() + }) + + it('should not throw error when undoing and redoing convert to path for a rectangle', function () { + cy.get('#tool_rect') + .click({ force: true }) + cy.get('#svgcontent') + .trigger('mousedown', 150, 150, { force: true }) + .trigger('mousemove', 250, 200, { force: true }) + .trigger('mouseup', { force: true }) + cy.get('#tool_topath') // Check if undo redo is correct for tool_topath with tool_rect + .click({ force: true }) + cy.get('#tool_undo') + .click({ force: true }) + cy.get('#tool_redo') + .click({ force: true }) + cy.get('#tool_undo') // Do twice just to make sure + .click({ force: true }) + cy.get('#tool_redo') + .click({ force: true }) + }) +}) diff --git a/src/svgcanvas/utilities.js b/src/svgcanvas/utilities.js index f55098bd..c4f84a82 100644 --- a/src/svgcanvas/utilities.js +++ b/src/svgcanvas/utilities.js @@ -760,11 +760,11 @@ export const convertToPath = (elem, attrs, svgCanvas) => { } const { nextSibling } = elem - batchCmd.addSubCommand(new svgCanvas.history.RemoveElementCommand(elem, nextSibling, parent)) - batchCmd.addSubCommand(new svgCanvas.history.InsertElementCommand(path)) - + batchCmd.addSubCommand(new svgCanvas.history.RemoveElementCommand(elem, nextSibling, elem.parentNode)) svgCanvas.clearSelection() elem.remove() + + batchCmd.addSubCommand(new svgCanvas.history.InsertElementCommand(path)) path.setAttribute('id', id) path.removeAttribute('visibility') svgCanvas.addToSelection([path], true)