From a97e61803c4894ea4c55f2aaf4fc53485331bb04 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Wed, 29 May 2013 10:32:11 -0700 Subject: [PATCH] Refine selection behavior when dragging a node * Preserve the sidebar state (fixes #1401) * Show vertices of selected way (fixes #1478) * Reselect exact previous selection when finished --- js/id/modes/drag_node.js | 16 ++++++++++++---- js/id/modes/select.js | 4 +++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/js/id/modes/drag_node.js b/js/id/modes/drag_node.js index 6bc42ed37..cb6ee6cda 100644 --- a/js/id/modes/drag_node.js +++ b/js/id/modes/drag_node.js @@ -8,6 +8,7 @@ iD.modes.DragNode = function(context) { activeIDs, wasMidpoint, cancelled, + selection = [], hover = iD.behavior.Hover(context).altDisables(true); function edge(point, size) { @@ -120,7 +121,6 @@ iD.modes.DragNode = function(context) { connectAnnotation(d)); } else if (d.type === 'node' && d.id !== entity.id) { - // `entity` is last so it will survive and it's parent ways can be selected below. context.replace( iD.actions.Connect([d.id, entity.id]), connectAnnotation(d)); @@ -136,11 +136,13 @@ iD.modes.DragNode = function(context) { moveAnnotation(entity)); } - var parentWays = _.pluck(context.graph().parentWays(entity), 'id'); + var reselection = selection.filter(function(id) { + return context.graph().hasEntity(id); + }); - if (parentWays.length) { + if (reselection.length) { context.enter( - iD.modes.Select(context, parentWays) + iD.modes.Select(context, reselection) .suppressMenu(true)); } else { context.enter(iD.modes.Browse(context)); @@ -193,6 +195,12 @@ iD.modes.DragNode = function(context) { stopNudge(); }; + mode.selection = function(_) { + if (!arguments.length) return selection; + selection = _; + return mode; + }; + mode.behavior = behavior; return mode; diff --git a/js/id/modes/select.js b/js/id/modes/select.js index 3b7c47191..54841b646 100644 --- a/js/id/modes/select.js +++ b/js/id/modes/select.js @@ -10,7 +10,9 @@ iD.modes.Select = function(context, selection) { iD.behavior.Hover(context), iD.behavior.Select(context), iD.behavior.Lasso(context), - iD.modes.DragNode(context).behavior], + iD.modes.DragNode(context) + .selection(selection) + .behavior], inspector, radialMenu, newFeature = false,