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);