mirror of
https://github.com/FoggedLens/iD.git
synced 2026-03-24 13:00:26 +01:00
When deleting a vertex, reselect another vertex if possible
Fixes #1457.
This commit is contained in:
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user