Merge pull request #208 from iuyiuy/setSvgString_without_undo

Add ability to set the svg drawing without adding to the undo stack.
This commit is contained in:
Jeff Schiller
2018-02-27 07:04:09 -08:00
committed by GitHub

View File

@@ -3834,7 +3834,7 @@ this.svgToString = function(elem, indent) {
var el = this; var el = this;
// for some elements have no attribute // for some elements have no attribute
var uri = this.namespaceURI; var uri = this.namespaceURI;
if(uri && !nsuris[uri] && nsMap[uri] && nsMap[uri] !== 'xmlns' && nsMap[uri] !== 'xml' ) { if (uri && !nsuris[uri] && nsMap[uri] && nsMap[uri] !== 'xmlns' && nsMap[uri] !== 'xml' ) {
nsuris[uri] = true; nsuris[uri] = true;
out.push(' xmlns:' + nsMap[uri] + '="' + uri +'"'); out.push(' xmlns:' + nsMap[uri] + '="' + uri +'"');
} }
@@ -4456,10 +4456,13 @@ var convertToGroup = this.convertToGroup = function(elem) {
// //
// Parameters: // Parameters:
// xmlString - The SVG as XML text. // xmlString - The SVG as XML text.
// preventUndo - Boolean (defaults to false) indicating if we want to do the
// changes without adding them to the undo stack - e.g. for initializing a
// drawing on page load.
// //
// Returns: // Returns:
// This function returns false if the set was unsuccessful, true otherwise. // This function returns false if the set was unsuccessful, true otherwise.
this.setSvgString = function(xmlString) { this.setSvgString = function(xmlString, preventUndo) {
try { try {
// convert string into XML document // convert string into XML document
var newDoc = svgedit.utilities.text2xml(xmlString); var newDoc = svgedit.utilities.text2xml(xmlString);
@@ -4613,7 +4616,7 @@ this.setSvgString = function(xmlString) {
svgedit.path.clearData(); svgedit.path.clearData();
svgroot.appendChild(selectorManager.selectorParentGroup); svgroot.appendChild(selectorManager.selectorParentGroup);
addCommandToHistory(batchCmd); if (!preventUndo) addCommandToHistory(batchCmd);
call('changed', [svgcontent]); call('changed', [svgcontent]);
} catch(e) { } catch(e) {
console.log(e); console.log(e);