Fix Issue 159: loop the right way when cloning elements

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@520 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Jeff Schiller 2009-09-01 19:47:25 +00:00
parent ee2e362b1a
commit 3557a0a94b
1 changed files with 11 additions and 7 deletions

View File

@ -2902,17 +2902,21 @@ function SvgCanvas(c)
// this creates deep DOM copies (clones) of all selected elements // this creates deep DOM copies (clones) of all selected elements
this.cloneSelectedElements = function() { this.cloneSelectedElements = function() {
var batchCmd = new BatchCommand("Clone Elements"); var batchCmd = new BatchCommand("Clone Elements");
var copiedElements = []; // find all the elements selected (stop at first null)
var i = selectedElements.length; var len = selectedElements.length;
while(i--) { for (var i = 0; i < len; ++i) {
var elem = selectedElements[i]; var elem = selectedElements[i];
if (elem == null) break; if (elem == null) break;
copiedElements.push(elem.cloneNode(true));
} }
// use slice to quickly get the subset of elements we need
var copiedElements = selectedElements.slice(0,i);
this.clearSelection(); this.clearSelection();
var len = copiedElements.length; // note that we loop in the reverse way because of the way elements are added
for (var i = 0; i < len; ++i) { // to the selectedElements array (top-first)
var elem = copiedElements[i]; var i = copiedElements.length;
while (i--) {
// clone each element and replace it within copiedElements
var elem = copiedElements[i] = copiedElements[i].cloneNode(true);
elem.removeAttribute("id"); elem.removeAttribute("id");
elem.id = getNextId(); elem.id = getNextId();
svgroot.appendChild(elem); svgroot.appendChild(elem);