diff --git a/modules/actions/disconnect.js b/modules/actions/disconnect.js index b58ab7d2f..169dbf92e 100644 --- a/modules/actions/disconnect.js +++ b/modules/actions/disconnect.js @@ -59,6 +59,9 @@ export function actionDisconnect(nodeId, newNodeId) { } else { way.nodes.forEach(function(waynode, index) { if (waynode === nodeId) { + if (way.isClosed() && parentWays.length > 1 && wayIds && wayIds.indexOf(way.id) !== -1 && index === way.nodes.length-1) { + return; + } candidates.push({ wayID: way.id, index: index }); } }); diff --git a/modules/operations/disconnect.js b/modules/operations/disconnect.js index b9ede9fd3..55a12831c 100644 --- a/modules/operations/disconnect.js +++ b/modules/operations/disconnect.js @@ -4,8 +4,15 @@ import { behaviorOperation } from '../behavior/index'; export function operationDisconnect(selectedIDs, context) { - var vertices = selectedIDs.filter(function(id) { - return context.geometry(id) === 'vertex'; + var vertices = [], + ways = []; + + selectedIDs.forEach(function(id) { + if (context.geometry(id) === 'vertex') { + vertices.push(id); + } else { + ways.push(id); + } }); var entityID = vertices[0]; @@ -23,7 +30,7 @@ export function operationDisconnect(selectedIDs, context) { operation.available = function() { - return vertices.length === 1; + return vertices.length === 1 && ways.every(function(way) { return context.graph().entity(way).nodes.includes(vertices[0]); }); }; diff --git a/test/spec/actions/disconnect.js b/test/spec/actions/disconnect.js index a985933d0..703ffef88 100644 --- a/test/spec/actions/disconnect.js +++ b/test/spec/actions/disconnect.js @@ -180,6 +180,35 @@ describe('iD.actionDisconnect', function () { expect(graph.entity('|').nodes).to.eql(['d', 'b']); }); + it('preserves the closed way when part of a larger disconnect operation', function () { + // Situation: + // a ---- bb === c + // = == + // = == + // d + // Disconnect - at b (whilst == is selected). + // + // Expected result: + // a ---- b ee === c + // = == + // = == + // d + // + var graph = iD.coreGraph([ + iD.osmNode({id: 'a'}), + iD.osmNode({id: 'b'}), + iD.osmNode({id: 'c'}), + iD.osmNode({id: 'd'}), + iD.osmWay({id: '-', nodes: ['a', 'b']}), + iD.osmWay({id: '=', nodes: ['b', 'c', 'd', 'b']}) + ]); + + graph = iD.actionDisconnect('b', 'e').limitWays(['='])(graph); + + expect(graph.entity('-').nodes).to.eql(['a', 'b']); + expect(graph.entity('=').nodes).to.eql(['e', 'c', 'd', 'e']); + }); + it('replaces later occurrences in a self-intersecting way', function() { // Situtation: // a --- b