From fc692d870734cbaea3868cfed7fd750ee8883b57 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 31 May 2013 17:36:08 -0700 Subject: [PATCH] When deleting a vertex, reselect another vertex if possible Fixes #1457. --- js/id/operations/delete.js | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/js/id/operations/delete.js b/js/id/operations/delete.js index 0ac6b5108..05f55d739 100644 --- a/js/id/operations/delete.js +++ b/js/id/operations/delete.js @@ -2,19 +2,47 @@ iD.operations.Delete = function(selection, context) { var action = iD.actions.DeleteMultiple(selection); var operation = function() { - var annotation; + var annotation, + mode; - if (selection.length === 1) { - annotation = t('operations.delete.annotation.' + context.geometry(selection[0])); - } else { + if (selection.length > 1) { annotation = t('operations.delete.annotation.multiple', {n: selection.length}); + mode = iD.modes.Browse(context); + } else { + var id = selection[0], + entity = context.entity(id), + geometry = context.geometry(id), + parents = context.graph().parentWays(entity), + parent = parents[0]; + + annotation = t('operations.delete.annotation.' + geometry); + mode = iD.modes.Browse(context); + + // Select the next closest node in the way. + if (geometry === 'vertex' && parents.length === 1 && parent.nodes.length > 2) { + var nodes = parent.nodes, + i = nodes.indexOf(id); + + if (i === 0) { + i++; + } else if (i === nodes.length - 1) { + i--; + } else { + var a = iD.geo.dist(entity.loc, context.entity(nodes[i - 1]).loc), + b = iD.geo.dist(entity.loc, context.entity(nodes[i + 1]).loc); + i = a < b ? i - 1 : i + 1; + } + + mode = iD.modes.Select(context, [nodes[i]]); + } } context.perform( action, annotation); - context.enter(iD.modes.Browse(context)); + context.enter(mode); + }; operation.available = function() {