From be71554f612630a6872bd3b2576dff8c01a0759f Mon Sep 17 00:00:00 2001 From: Quincy Morgan Date: Thu, 21 Feb 2019 09:22:03 -0500 Subject: [PATCH] Fix a bug where all data would disappear when switching modes while drawing a way (close #5917) --- modules/behavior/draw_way.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/modules/behavior/draw_way.js b/modules/behavior/draw_way.js index 847803d15..c93b5f1a1 100644 --- a/modules/behavior/draw_way.js +++ b/modules/behavior/draw_way.js @@ -152,9 +152,7 @@ export function behaviorDrawWay(context, wayID, index, mode, startGraph, baselin if (context.graph() === baselineGraph) { // We've undone back to the beginning // baselineGraph may be behind startGraph if this way was added rather than continued - while (context.graph() !== startGraph) { - context.pop(); - } + resetContextGraphToStartGraph(); context.enter(modeSelect(context, [wayID])); } else { // Remove whatever segment was drawn previously and continue drawing @@ -196,13 +194,19 @@ export function behaviorDrawWay(context, wayID, index, mode, startGraph, baselin .on('undone.draw', undone); }; + function resetContextGraphToStartGraph() { + while (context.graph() !== startGraph) { + context.pop(); + } + } drawWay.off = function(surface) { // Drawing was interrupted unexpectedly. // This can happen if the user changes modes, // clicks geolocate button, a hashchange event occurs, etc. if (_tempEdits) { - context.history().reset('drawWay-initial'); + context.pop(_tempEdits); + resetContextGraphToStartGraph(); } context.map() @@ -333,9 +337,7 @@ export function behaviorDrawWay(context, wayID, index, mode, startGraph, baselin context.pop(_tempEdits); _tempEdits = 0; - while (context.graph() !== startGraph) { - context.pop(); - } + resetContextGraphToStartGraph(); window.setTimeout(function() { context.map().dblclickEnable(true);