Merge pull request #208 from iuyiuy/setSvgString_without_undo

Add ability to set the svg drawing without adding to the undo stack.
master
Jeff Schiller 2018-02-27 07:04:09 -08:00 committed by GitHub
commit 396cce40eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 3 deletions

View File

@ -3834,7 +3834,7 @@ this.svgToString = function(elem, indent) {
var el = this;
// for some elements have no attribute
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;
out.push(' xmlns:' + nsMap[uri] + '="' + uri +'"');
}
@ -4456,10 +4456,13 @@ var convertToGroup = this.convertToGroup = function(elem) {
//
// Parameters:
// 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:
// This function returns false if the set was unsuccessful, true otherwise.
this.setSvgString = function(xmlString) {
this.setSvgString = function(xmlString, preventUndo) {
try {
// convert string into XML document
var newDoc = svgedit.utilities.text2xml(xmlString);
@ -4613,7 +4616,7 @@ this.setSvgString = function(xmlString) {
svgedit.path.clearData();
svgroot.appendChild(selectorManager.selectorParentGroup);
addCommandToHistory(batchCmd);
if (!preventUndo) addCommandToHistory(batchCmd);
call('changed', [svgcontent]);
} catch(e) {
console.log(e);