diff --git a/js/id/actions/delete_way.js b/js/id/actions/delete_way.js index 95888470e..9d98a697b 100644 --- a/js/id/actions/delete_way.js +++ b/js/id/actions/delete_way.js @@ -1,5 +1,11 @@ // https://github.com/openstreetmap/potlatch2/blob/master/net/systemeD/halcyon/connection/actions/DeleteWayAction.as iD.actions.DeleteWay = function(wayId) { + function deleteNode(node, graph) { + return !graph.parentWays(node).length && + !graph.parentRelations(node).length && + !node.hasInterestingTags(); + } + return function(graph) { var way = graph.entity(wayId); @@ -8,20 +14,12 @@ iD.actions.DeleteWay = function(wayId) { graph = graph.replace(parent.removeMember(wayId)); }); - way.nodes.forEach(function(nodeId) { - var node = graph.entity(nodeId); - - // Circular ways include nodes more than once, so they - // can be deleted on earlier iterations of this loop. - if (!node) return; - + _.uniq(way.nodes).forEach(function(nodeId) { graph = graph.replace(way.removeNode(nodeId)); - if (!graph.parentWays(node).length && - !graph.parentRelations(node).length) { - if (!node.hasInterestingTags()) { - graph = graph.remove(node); - } + var node = graph.entity(nodeId); + if (deleteNode(node, graph)) { + graph = graph.remove(node); } }); diff --git a/test/spec/actions/delete_way.js b/test/spec/actions/delete_way.js index 130f5f759..a42ca3e38 100644 --- a/test/spec/actions/delete_way.js +++ b/test/spec/actions/delete_way.js @@ -47,7 +47,7 @@ describe("iD.actions.DeleteWay", function() { c = iD.Node(), way = iD.Way({nodes: [a.id, b.id, c.id, a.id]}), action = iD.actions.DeleteWay(way.id), - graph = iD.Graph([a, b, way]).update(action); + graph = iD.Graph([a, b, c, way]).update(action); expect(graph.entity(a.id)).to.be.undefined; expect(graph.entity(b.id)).to.be.undefined; expect(graph.entity(c.id)).to.be.undefined;