From 5e15483254d2d351eadfafe6eaf3c710cb8880be Mon Sep 17 00:00:00 2001 From: Jeff Schiller Date: Mon, 13 Jul 2009 03:23:58 +0000 Subject: [PATCH] Preserve comments when editing SVG source git-svn-id: http://svg-edit.googlecode.com/svn/trunk@315 eee81c28-f429-11dd-99c0-75d572ba1ddd --- editor/svg-editor.js | 19 +++++-------------- editor/svgcanvas.js | 17 ++++++++++++++--- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/editor/svg-editor.js b/editor/svg-editor.js index 7b689539..1dfd2753 100644 --- a/editor/svg-editor.js +++ b/editor/svg-editor.js @@ -410,11 +410,10 @@ function svg_edit_setup() { svgCanvas.redo(); }; - // TODO: prevent 'u' from showing up in the textarea // TODO: properly size the text area during resize // TODO: properly handle error conditions (error msg dialog) // TODO: prevent @style showing up on the svg element - // TODO: create new button or Source Editor + // TODO: create new button for Source Editor var showSourceEditor = function(){ if (editingsource) return; editingsource = true; @@ -437,6 +436,9 @@ function svg_edit_setup() { if (svgCanvas.setSvgString($('#svg_source_textarea').val())) { console.log('yo'); } + else { + alert('There were parsing errors in your SVG source.\nReverting back to original SVG source.'); + } $('#svg_source_editor').hide(); editingsource = false; $('#svg_source_textarea').blur(); @@ -527,18 +529,7 @@ function svg_edit_setup() { $(document).bind('keydown', {combi:'y', disableInInput: true}, clickRedo); $(document).bind('keydown', {combi:'u', disableInInput: true}, function(evt){showSourceEditor();evt.preventDefault();}); $(document).bind('keydown', {combi:'esc', disableInInput: false}, hideSourceEditor); - // temporary binding to test setSvgString() - /* - $(document).bind('keydown', {combi:'t', disableInInput: true}, function() { - if (svgCanvas.setSvgString( -'')) { - updateContextPanel(); - var dims = svgCanvas.getResolution(); - changeResolution(dims[0],dims[1]); - } - }); - */ var colorPicker = function(elem) { var oldbg = elem.css('background'); var color = elem.css('background-color'); @@ -684,7 +675,7 @@ function svg_edit_setup() { function changeResolution(x,y) { $('#resolution').val(x+'x'+y); - $('#svgroot').css( { 'width': x+'px', 'height': y+'px' } ); +// $('#svgroot').css( { 'width': x+'px', 'height': y+'px' } ); $('#svgcanvas').css( { 'width': x+'px', 'height': y+'px' } ); } diff --git a/editor/svgcanvas.js b/editor/svgcanvas.js index b721c220..fd26b3ca 100644 --- a/editor/svgcanvas.js +++ b/editor/svgcanvas.js @@ -486,6 +486,7 @@ function SvgCanvas(c) } undoStack.push(cmd); undoStackPointer = undoStack.length; + console.log(undoStack); }; // private functions @@ -617,16 +618,26 @@ function SvgCanvas(c) { var child = childs.item(i); if (child.id == "selectorParentGroup") continue; - if (child.nodeType == 1) { // element node + switch(child.nodeType) { + case 1: // element node out.push("\n"); out.push(svgToString(childs.item(i), indent)); - } else if (child.nodeType == 3) { // text node + break; + case 3: // text node var str = child.nodeValue.replace(/^\s+|\s+$/g, ""); if (str != "") { bOneLine = true; out.push(str + ""); } - } + break; + case 8: // comment + out.push("\n"); + out.push(new Array(indent+1).join(" ")); + out.push(""); + break; + } // switch on node type } indent--; if (!bOneLine) {