mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-20 23:44:47 +02:00
When connecting nodes, prefer to keep an existing (not new) node
(closes #4974, closes #4674)
This commit is contained in:
@@ -3,8 +3,8 @@ import { actionDeleteNode } from './delete_node';
|
||||
|
||||
// Connect the ways at the given nodes.
|
||||
//
|
||||
// The last node will survive. All other nodes will be replaced with
|
||||
// the surviving node in parent ways, and then removed.
|
||||
// First choose a node to be the survivor, with preference given
|
||||
// to an existing (not new) node.
|
||||
//
|
||||
// Tags and relation memberships of of non-surviving nodes are merged
|
||||
// to the survivor.
|
||||
@@ -17,11 +17,20 @@ import { actionDeleteNode } from './delete_node';
|
||||
//
|
||||
export function actionConnect(nodeIds) {
|
||||
return function(graph) {
|
||||
var last = nodeIds[nodeIds.length - 1];
|
||||
var survivor = graph.entity(last);
|
||||
var survivor;
|
||||
var node;
|
||||
var i;
|
||||
|
||||
for (var i = 0; i < nodeIds.length - 1; i++) {
|
||||
var node = graph.entity(nodeIds[i]);
|
||||
// Choose a survivor node, prefer an existing (not new) node - #4974
|
||||
for (i = 0; i < nodeIds.length; i++) {
|
||||
survivor = graph.entity(nodeIds[i]);
|
||||
if (survivor.version) break; // found one
|
||||
}
|
||||
|
||||
// Replace all non-surviving nodes with the survivor and merge tags.
|
||||
for (i = 0; i < nodeIds.length; i++) {
|
||||
node = graph.entity(nodeIds[i]);
|
||||
if (node.id === survivor.id) continue;
|
||||
|
||||
/* eslint-disable no-loop-func */
|
||||
graph.parentWays(node).forEach(function(parent) {
|
||||
|
||||
Reference in New Issue
Block a user