From f76f10e464845e1138841f1241cfef105d69ef3d Mon Sep 17 00:00:00 2001 From: Alexis Deveria Date: Wed, 30 Dec 2009 20:55:53 +0000 Subject: [PATCH] Fixed issue 383: Delete unclosed path node makes the path appear as closed. Also prevented deletion of last two nodes git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1131 eee81c28-f429-11dd-99c0-75d572ba1ddd --- editor/svgcanvas.js | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/editor/svgcanvas.js b/editor/svgcanvas.js index a5f538ea..0fd426aa 100644 --- a/editor/svgcanvas.js +++ b/editor/svgcanvas.js @@ -4212,11 +4212,15 @@ function BatchCommand(text) { // current_path.setAttribute("d", convertToD(current_path.pathSegList)); }, deletePathNode: function() { + var is_closed = pathIsClosed(); + + // TODO: Make delete node button disabled when there's only 2 nodes + if(current_path_pts.length <= (is_closed?6:4)) return; + var last_pt = current_path_pts.length/2 - 1; var pt = current_path_pt, list = current_path.pathSegList; var cur_item = list.getItem(pt); - var next_item = list.getItem(pt+1); - + if(pt == 0) { var next_x = getPathPoint(1)[0]; var next_y = getPathPoint(1)[1]; @@ -4224,11 +4228,13 @@ function BatchCommand(text) { replacePathSeg(2, 1, [next_x, next_y]); // Reposition last node - var last_item = list.getItem(last_pt); - replacePathSeg(4, last_pt, [next_x, next_y]); - removeControlPointGrips(last_pt - 1); - current_path_pts.splice(last_pt*2, 2, next_x, next_y); - current_path_pts.splice(0, 2); + if(is_closed) { + var last_item = list.getItem(last_pt); + replacePathSeg(4, last_pt, [next_x, next_y]); + removeControlPointGrips(last_pt - 1); + current_path_pts.splice(last_pt*2, 2, next_x, next_y); + current_path_pts.splice(0, 2); + } } else { current_path_pts.splice(pt*2, 2); } @@ -4241,6 +4247,10 @@ function BatchCommand(text) { var cp = $(current_path); cp.attr('d',cp.attr('d')); } + if(pt == last_pt && !is_closed) { + pt--; + } + addNodeToSelection(pt); }, setPointContainerTransform: setPointContainerTransform,