From 2d0e4fab270fbaf95496e6a3d168d23b5266b86c Mon Sep 17 00:00:00 2001 From: Mark MacKay Date: Thu, 13 May 2021 14:15:39 -0500 Subject: [PATCH] save canvas content restored --- src/js/editor.js | 8 ++++---- src/js/start.js | 3 +-- src/js/svgcanvas.js | 7 +++++++ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/js/editor.js b/src/js/editor.js index fec742e..e5fb690 100644 --- a/src/js/editor.js +++ b/src/js/editor.js @@ -141,8 +141,9 @@ MD.Editor = function(){ function escapeMode(){ for (key in editor.modal) editor.modal[key].close(); state.set("canvasMode", "select"); - if ($("#cur_context_panel").is(":visible")) + if ($("#cur_context_panel").is(":visible")) { svgCanvas.leaveContext() + } else state.set("canvasContent", svgCanvas.getSvgString()) } @@ -194,8 +195,7 @@ MD.Editor = function(){ elems: elems }); - // todo svgCanvas.getCurrentContext is needed - if (!$("#cur_context_panel").is(":visible")) + if (!svgCanvas.getContext()) state.set("canvasContent", svgCanvas.getSvgString()) } @@ -203,7 +203,7 @@ MD.Editor = function(){ if (attr === "opacity") value *= 0.01; if (completed) { svgCanvas.changeSelectedAttribute(attr, value); - state.set("canvasContent", serializer.serializeToString(svgCanvas.getContentElem())); + state.set("canvasContent", svgCanvas.getSvgString()); } else svgCanvas.changeSelectedAttributeNoUndo(attr, value); } diff --git a/src/js/start.js b/src/js/start.js index 54ef980..df77ef0 100644 --- a/src/js/start.js +++ b/src/js/start.js @@ -1,6 +1,7 @@ // globals const svgCanvas = new $.SvgCanvas(document.getElementById("svgcanvas")); const editor = new MD.Editor(); +const state = new State(); editor.modal = { about: new MD.Modal({ @@ -113,10 +114,8 @@ svgCanvas.bind("extension_added", editor.extensionAdded); svgCanvas.textActions.setInputElem($("#text")[0]); const shapeLib = svgCanvas.addExtension.apply(this, ["shapes", MD.Shapelib]); const eyedropper = svgCanvas.addExtension.apply(this, ["eyedropper", MD.Eyedropper]); -const state = new State(); state.set("canvasId", t("Untitled")); state.set("canvasMode", state.get("canvasMode")); -state.set("canvasSize", state.get("canvasSize")); svgCanvas.setSvgString(state.get("canvasContent")); editor.paintBox.fill.setPaint(state.get("canvasFill")); editor.paintBox.stroke.setPaint(state.get("canvasStroke")); diff --git a/src/js/svgcanvas.js b/src/js/svgcanvas.js index 5099307..b39901f 100644 --- a/src/js/svgcanvas.js +++ b/src/js/svgcanvas.js @@ -6461,6 +6461,13 @@ var leaveContext = this.leaveContext = function() { current_group = null; } +// Function: getContext +// Get the current context (in-group editing) +var getContext = this.getContext = function() { + return current_group; +} + + // Function: setContext // Set the current context (for in-group editing) var setContext = this.setContext = function(elem) {