diff --git a/js/id/actions/disconnect.js b/js/id/actions/disconnect.js index 878904dac..b9220fa69 100644 --- a/js/id/actions/disconnect.js +++ b/js/id/actions/disconnect.js @@ -22,7 +22,7 @@ iD.actions.Disconnect = function(nodeId, newNodeId) { replacements.forEach(function(replacement) { var newNode = iD.Node({id: newNodeId, loc: node.loc, tags: node.tags}); graph = graph.replace(newNode); - graph = graph.replace(replacement.way.updateNode(newNode.id, replacement.index)); + graph = graph.replace(graph.entity(replacement.wayID).updateNode(newNode.id, replacement.index)); }); return graph; @@ -41,7 +41,7 @@ iD.actions.Disconnect = function(nodeId, newNodeId) { parent.nodes.forEach(function(waynode, index) { if (waynode === nodeId) { - candidates.push({way: parent, index: index}); + candidates.push({wayID: parent.id, index: index}); } }); }); diff --git a/test/spec/actions/disconnect.js b/test/spec/actions/disconnect.js index 1c8873dfb..d91296c0a 100644 --- a/test/spec/actions/disconnect.js +++ b/test/spec/actions/disconnect.js @@ -128,6 +128,30 @@ describe("iD.actions.Disconnect", function () { expect(graph.entity('w').nodes).to.eql(['a', 'b', 'c', 'd']); }); + it("disconnects a way with multiple intersection points", function() { + // Situtation: + // a = b - c + // | | + // e - d + // Where b starts/ends -. + // Disconnect at b + + var graph = iD.Graph([ + iD.Node({id: 'a'}), + iD.Node({id: 'b'}), + iD.Node({id: 'c'}), + iD.Node({id: 'd'}), + iD.Node({id: 'e'}), + iD.Way({id: 'w1', nodes: ['a', 'b']}), + iD.Way({id: 'w2', nodes: ['b', 'c', 'd', 'e', 'b']}) + ]); + + graph = iD.actions.Disconnect('b', '*')(graph); + + expect(graph.entity('w1').nodes).to.eql(['a', 'b']); + expect(graph.entity('w2').nodes).to.eql(['*', 'c', 'd', 'e', '*']); + }); + it("copies location and tags to the new nodes", function () { var tags = {highway: 'traffic_signals'}, loc = [1, 2],