From c53ad929c677e1b2873d29d0a26e589531db6bad Mon Sep 17 00:00:00 2001 From: Jeff Schiller Date: Mon, 31 Aug 2009 18:02:15 +0000 Subject: [PATCH] Fix Issue 141: can edit poly after pasting in SVG source git-svn-id: http://svg-edit.googlecode.com/svn/trunk@509 eee81c28-f429-11dd-99c0-75d572ba1ddd --- editor/svgcanvas.js | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/editor/svgcanvas.js b/editor/svgcanvas.js index 5f66d1c1..6e1414be 100644 --- a/editor/svgcanvas.js +++ b/editor/svgcanvas.js @@ -1730,19 +1730,23 @@ function SvgCanvas(c) var addAllPointGripsToPoly = function() { // loop through and hide all pointgrips - var i = current_poly_pts.length; - while(i) { - i -= 2; + var len = current_poly_pts.length; + for (var i = 0; i < len; i += 2) { var grip = document.getElementById("polypointgrip_"+i/2); - assignAttributes(grip, { - 'cx': current_poly_pts[i], - 'cy': current_poly_pts[i+1], - 'display': 'inline' - }); + if (grip) { + assignAttributes(grip, { + 'cx': current_poly_pts[i], + 'cy': current_poly_pts[i+1], + 'display': 'inline' + }); + } + else { + addPointGripToPoly(current_poly_pts[i], current_poly_pts[i+1],i/2); + } } }; - var addPointGripToPoly = function(x,y) { + var addPointGripToPoly = function(x,y,index) { // create the container of all the point grips var pointGripContainer = document.getElementById("polypointgrip_container"); if (!pointGripContainer) { @@ -1751,9 +1755,6 @@ function SvgCanvas(c) pointGripContainer.id = "polypointgrip_container"; } - // get index of this point - var index = current_poly_pts.length/2 - 1; - var pointGrip = document.getElementById("polypointgrip_"+index); // create it if (!pointGrip) { @@ -2000,7 +2001,7 @@ function SvgCanvas(c) 'x2': x, 'y2': y }); - addPointGripToPoly(x,y); + addPointGripToPoly(x,y,0); } else { // determine if we clicked on an existing point @@ -2057,7 +2058,7 @@ function SvgCanvas(c) 'x2': x, 'y2': y }); - addPointGripToPoly(x,y); + addPointGripToPoly(x,y,(current_poly_pts.length/2 - 1)); } keep = true; }