From 4ee5d7334b29a85790da5d34c1d5415bacb873b9 Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Mon, 8 May 2017 01:37:38 -0400 Subject: [PATCH] Fix spacebar drawing and hover in Firefox - don't match active node (closes #4016) --- modules/behavior/draw.js | 8 +++++--- modules/behavior/draw_way.js | 7 +++++++ modules/behavior/hover.js | 10 +++++----- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/modules/behavior/draw.js b/modules/behavior/draw.js index 9a221e897..f5f082ab5 100644 --- a/modules/behavior/draw.js +++ b/modules/behavior/draw.js @@ -124,6 +124,9 @@ export function behaviorDraw(context) { function space() { + d3.event.preventDefault(); + d3.event.stopPropagation(); + var currSpace = context.mouse(); if (disableSpace && lastSpace) { var dist = geoEuclideanDistance(lastSpace, currSpace); @@ -139,13 +142,12 @@ export function behaviorDraw(context) { disableSpace = true; d3.select(window).on('keyup.space-block', function() { - disableSpace = false; - d3.select(window).on('keyup.space-block', null); d3.event.preventDefault(); d3.event.stopPropagation(); + disableSpace = false; + d3.select(window).on('keyup.space-block', null); }); - d3.event.preventDefault(); click(); } diff --git a/modules/behavior/draw_way.js b/modules/behavior/draw_way.js index 5c1e34971..80bba15c8 100644 --- a/modules/behavior/draw_way.js +++ b/modules/behavior/draw_way.js @@ -255,6 +255,13 @@ export function behaviorDrawWay(context, wayId, index, mode, startGraph) { // Avoid creating duplicate segments if (origWay.areAdjacent(node.id, origWay.nodes[origWay.nodes.length - 1])) return; + // Clicks should not occur on the drawing node, however a space keypress can + // sometimes grab that node's datum (before it gets classed as `active`?) #4016 + if (node.id === end.id) { + drawWay.add(node.loc); + return; + } + context.pop(tempEdits); context.perform( diff --git a/modules/behavior/hover.js b/modules/behavior/hover.js index fc073f086..4d0bb7882 100644 --- a/modules/behavior/hover.js +++ b/modules/behavior/hover.js @@ -16,7 +16,7 @@ import { utilRebind } from '../util/rebind'; export function behaviorHover(context) { var dispatch = d3.dispatch('hover'), _selection = d3.select(null), - newNode = null, + newId = null, buttonDown, altDisables, target; @@ -52,7 +52,7 @@ export function behaviorHover(context) { var hover = function(selection) { _selection = selection; - newNode = null; + newId = null; _selection .on('mouseover.hover', mouseover) @@ -101,12 +101,12 @@ export function behaviorHover(context) { _selection.selectAll('.hover-suppressed') .classed('hover-suppressed', false); - if (target instanceof osmEntity && target !== newNode) { + if (target instanceof osmEntity && target.id !== newId) { // If drawing a way, don't hover on a node that was just placed. #3974 var mode = context.mode() && context.mode().id; - if ((mode === 'draw-line' || mode === 'draw-area') && !newNode && target.type === 'node') { - newNode = target; + if ((mode === 'draw-line' || mode === 'draw-area') && !newId && target.type === 'node') { + newId = target.id; return; }