diff --git a/js/id/actions/split_way.js b/js/id/actions/split_way.js index 4b4152a99..d9081bb9d 100644 --- a/js/id/actions/split_way.js +++ b/js/id/actions/split_way.js @@ -1,7 +1,16 @@ // https://github.com/systemed/potlatch2/blob/master/net/systemeD/halcyon/connection/actions/SplitWayAction.as -iD.actions.SplitWay = function(nodeId, wayId) { +iD.actions.SplitWay = function(nodeId) { return function(graph) { - var way = graph.entity(wayId); - return graph.replace(way.update({nodes: nodes}), 'changed way direction'); + var parents = graph.parentWays(nodeId); + parents.forEach(function(way) { + var idx = _.indexOf(way.nodes, nodeId); + // Create a 'b' way that contains all of the tags in the second + // half of this way + var b = iD.Way({ tags: _.clone(way.tags), nodes: way.nodes.slice(idx) }); + graph = graph.replace(b); + // Reduce the original way to only contain the first set of nodes + graph = graph.replace(way.update({ nodes: way.nodes.slice(0, idx + 1) }), 'changed way direction'); + }); + return graph; }; }; diff --git a/js/id/modes/select.js b/js/id/modes/select.js index 2f917e77f..60fcbadfd 100644 --- a/js/id/modes/select.js +++ b/js/id/modes/select.js @@ -71,6 +71,11 @@ iD.modes.Select = function (entity) { iD.actions.ReverseWay(d.id), 'reversed a way'); + }).on('splitWay', function(d) { + mode.history.perform( + iD.actions.SplitWay(d.id), + 'split a way on a node'); + }).on('remove', function() { remove(); diff --git a/js/id/ui/inspector.js b/js/id/ui/inspector.js index 1a9865277..6c51d0d99 100644 --- a/js/id/ui/inspector.js +++ b/js/id/ui/inspector.js @@ -1,5 +1,5 @@ iD.Inspector = function() { - var event = d3.dispatch('changeTags', 'changeWayDirection', 'update', 'remove', 'close'), + var event = d3.dispatch('changeTags', 'changeWayDirection', 'update', 'remove', 'close', 'splitWay'), taginfo = iD.taginfo(); function drawhead(selection) {