From a18d690dd5a96608ba37543d43580fb44d4ac8b3 Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Wed, 3 May 2017 17:15:35 -0400 Subject: [PATCH] Don't let window.location changes happen during draw modes (closes #3996) --- modules/behavior/draw_way.js | 13 ++++++++++--- modules/behavior/hash.js | 10 +++++++--- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/modules/behavior/draw_way.js b/modules/behavior/draw_way.js index b5ab9d5b0..5c1e34971 100644 --- a/modules/behavior/draw_way.js +++ b/modules/behavior/draw_way.js @@ -125,8 +125,15 @@ export function behaviorDrawWay(context, wayId, index, mode, startGraph) { drawWay.off = function(surface) { - context.pop(tempEdits); - tempEdits = 0; + // Drawing was interrupted unexpectedly. + // This can happen if the user changes modes, + // clicks geolocate button, a hashchange event occurs, etc. + if (tempEdits) { + context.pop(tempEdits); + while (context.graph() !== startGraph) { + context.pop(); + } + } context.map() .on('drawn.draw', null); @@ -268,7 +275,7 @@ export function behaviorDrawWay(context, wayId, index, mode, startGraph) { tempEdits = 0; var way = context.hasEntity(wayId); - if (!way || origWay.isDegenerate()) { + if (!way || way.isDegenerate()) { drawWay.cancel(); return; } diff --git a/modules/behavior/hash.js b/modules/behavior/hash.js index 2e0723e5c..728bd8f6b 100644 --- a/modules/behavior/hash.js +++ b/modules/behavior/hash.js @@ -1,6 +1,7 @@ import * as d3 from 'd3'; import _ from 'lodash'; -import { utilQsString, utilStringQs } from '../util/index'; +import { modeBrowse } from '../modes'; +import { utilQsString, utilStringQs } from '../util'; export function behaviorHash(context) { @@ -14,8 +15,11 @@ export function behaviorHash(context) { if (args.length < 3 || args.some(isNaN)) { return true; // replace bogus hash } else if (s !== formatter(map).slice(1)) { - map.centerZoom([args[2], - Math.min(lat, Math.max(-lat, args[1]))], args[0]); + var mode = context.mode(); + if (mode && mode.id.match(/^draw/) !== null) { + context.enter(modeBrowse(context)); + } + map.centerZoom([args[2], Math.min(lat, Math.max(-lat, args[1]))], args[0]); } };