From a1987e21d91fae2c8bb9050d8ad809ca604ae888 Mon Sep 17 00:00:00 2001 From: Quincy Morgan <2046746+quincylvania@users.noreply.github.com> Date: Wed, 2 Sep 2020 11:07:09 -0400 Subject: [PATCH] Fix issue where undoing the second-to-first vertex of a way when drawing would undo to the initial state of the way (close #7772) --- modules/behavior/draw_way.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/modules/behavior/draw_way.js b/modules/behavior/draw_way.js index 48eb679f6..56c7ef5ab 100644 --- a/modules/behavior/draw_way.js +++ b/modules/behavior/draw_way.js @@ -195,23 +195,23 @@ export function behaviorDrawWay(context, wayID, mode, startGraph) { var nextMode; - if (context.graph() === startGraph) { // we've undone back to the beginning + if (context.graph() === startGraph) { + // We've undone back to the initial state before we started drawing. + // Just exit the draw mode without undoing whatever we did before + // we entered the draw mode. nextMode = modeSelect(context, [wayID]); } else { - context.history() - .on('undone.draw', null); - // remove whatever segment was drawn previously - context.undo(); + // The `undo` only removed the temporary edit, so here we have to + // manually undo to actually remove the last node we added. We can't + // use the `undo` function since the initial "add" graph doesn't have + // an annotation and so cannot be undone to. + context.pop(1); - if (context.graph() === startGraph) { // we've undone back to the beginning - nextMode = modeSelect(context, [wayID]); - } else { - // continue drawing - nextMode = mode; - } + // continue drawing + nextMode = mode; } - // clear the redo stack by adding and removing an edit + // clear the redo stack by adding and removing a blank edit context.perform(actionNoop()); context.pop(1);