From 5d73e45b50452d932013b533e065096fadeaadea Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 28 Jan 2013 17:26:06 -0500 Subject: [PATCH] Fix exiting draw mode via other means (fixes #503) --- js/id/behavior/draw_way.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/js/id/behavior/draw_way.js b/js/id/behavior/draw_way.js index 649d79e55..0e5bcf4fd 100644 --- a/js/id/behavior/draw_way.js +++ b/js/id/behavior/draw_way.js @@ -4,6 +4,7 @@ iD.behavior.DrawWay = function(wayId, headId, tailId, index, mode, baseGraph) { controller = mode.controller, event = d3.dispatch('add', 'addHead', 'addTail', 'addNode', 'addWay'), way = mode.history.graph().entity(wayId), + finished = false, hover, draw; var node = iD.Node({loc: map.mouseCoordinates()}), @@ -56,6 +57,9 @@ iD.behavior.DrawWay = function(wayId, headId, tailId, index, mode, baseGraph) { }; drawWay.off = function(surface) { + if (!finished) + history.pop(); + map.fastEnable(true) .minzoom(0) .tail(false); @@ -86,6 +90,7 @@ iD.behavior.DrawWay = function(wayId, headId, tailId, index, mode, baseGraph) { ReplaceTemporaryNode(node), annotation); + finished = true; controller.enter(mode); }; @@ -99,6 +104,7 @@ iD.behavior.DrawWay = function(wayId, headId, tailId, index, mode, baseGraph) { ReplaceTemporaryNode(newNode), annotation); + finished = true; controller.enter(mode); }; @@ -111,6 +117,7 @@ iD.behavior.DrawWay = function(wayId, headId, tailId, index, mode, baseGraph) { ReplaceTemporaryNode(newNode), annotation); + finished = true; controller.enter(mode); }; @@ -118,6 +125,7 @@ iD.behavior.DrawWay = function(wayId, headId, tailId, index, mode, baseGraph) { // nodes to be valid, it's selected. Otherwise, return to browse mode. drawWay.finish = function() { history.pop(); + finished = true; var way = history.graph().entity(wayId); if (way) { @@ -129,7 +137,11 @@ iD.behavior.DrawWay = function(wayId, headId, tailId, index, mode, baseGraph) { // Cancel the draw operation and return to browse, deleting everything drawn. drawWay.cancel = function() { - history.perform(d3.functor(baseGraph), 'cancelled drawing'); + history.perform( + d3.functor(baseGraph), + 'cancelled drawing'); + + finished = true; controller.enter(iD.modes.Browse()); };