From 14fd8e09513951a378f4169da8aa2b47ca183fcd Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Wed, 12 Dec 2012 16:56:40 -0500 Subject: [PATCH] Delete ways and areas when they are down to one and two nodes --- js/id/modes/draw_area.js | 13 +++++++++++-- js/id/modes/draw_road.js | 18 +++++++++++++----- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/js/id/modes/draw_area.js b/js/id/modes/draw_area.js index abf84ac4a..3bfe5b947 100644 --- a/js/id/modes/draw_area.js +++ b/js/id/modes/draw_area.js @@ -8,7 +8,9 @@ iD.modes.DrawArea = function(wayId) { history = mode.history, controller = mode.controller, way = history.graph().entity(wayId), - headId = _.last(way.nodes), + headId = (way.nodes.length == 1) ? + way.nodes[0] : + way.nodes[way.nodes.length - 2], tailId = _.first(way.nodes), node = iD.Node({loc: map.mouseCoordinates()}); @@ -68,7 +70,14 @@ iD.modes.DrawArea = function(wayId) { iD.actions.DeleteNode(node.id), iD.actions.DeleteNode(headId)); - controller.enter(iD.modes.DrawArea(wayId)); + if (history.graph().fetch(wayId).nodes.length === 2) { + history.replace( + iD.actions.DeleteNode(way.nodes[0]), + iD.actions.DeleteWay(wayId)); + controller.enter(iD.modes.Browse()); + } else { + controller.enter(iD.modes.DrawArea(wayId)); + } } map.surface.on('mousemove.drawarea', mousemove); diff --git a/js/id/modes/draw_road.js b/js/id/modes/draw_road.js index 5e61ddc96..c78ff913d 100644 --- a/js/id/modes/draw_road.js +++ b/js/id/modes/draw_road.js @@ -74,22 +74,30 @@ iD.modes.DrawRoad = function(wayId, direction) { } }); - map.keybinding().on('⎋.drawroad', function() { + function esc() { history.replace( iD.actions.DeleteNode(node.id)); controller.enter(iD.modes.Browse()); - }); + } - map.keybinding().on('⌫.drawroad', function() { + function del() { d3.event.preventDefault(); history.replace( iD.actions.DeleteNode(node.id), iD.actions.DeleteNode(headId)); - controller.enter(iD.modes.DrawRoad(wayId, direction)); - }); + if (history.graph().fetch(wayId).nodes.length === 0) { + history.replace(iD.actions.DeleteWay(wayId)); + controller.enter(iD.modes.Browse()); + } else { + controller.enter(iD.modes.DrawRoad(wayId, direction)); + } + } + + map.keybinding().on('⎋.drawroad', esc); + map.keybinding().on('⌫.drawroad', del); }; mode.exit = function() {