Enforce either 0 or 2 selected vertices

This commit is contained in:
J Guthrie
2019-01-21 21:11:39 +00:00
committed by Bryan Housel
parent 24f83ba1ae
commit d07418c654
3 changed files with 21 additions and 3 deletions
+5 -2
View File
@@ -51,8 +51,11 @@ export function actionStraighten(selectedIDs, projection) {
// If user selected 2 nodes to straighten between, then slice nodes array to those nodes
if (selectedNodes.length) {
var startEndPoints = [nodes.indexOf(graph.entity(selectedNodes[0])), nodes.indexOf(graph.entity(selectedNodes[1]))].sort();
nodes = nodes.slice(startEndPoints[0], startEndPoints[1]+1);
startNode = nodes.indexOf(graph.entity(selectedNodes[0]));
endNode = nodes.indexOf(graph.entity(selectedNodes[1]));
var sortedStartEnd = [startNode, endNode].sort();
nodes = nodes.slice(sortedStartEnd[0], sortedStartEnd[1]+1);
}
return nodes;
+1 -1
View File
@@ -41,7 +41,7 @@ export function operationStraighten(selectedIDs, context) {
endNodes.push(entity.nodes[entity.nodes.length-1]);
}
if (_uniq(nodes).length <= 2 || selectedNodes.length > 2) return false;
if (_uniq(nodes).length <= 2 || ![0,2].includes(selectedNodes.length)) return false;
// Ensure all ways are connected (i.e. only one unique start point and one unique end point)
if (_difference(startNodes, endNodes).length !== 1 ||
+15
View File
@@ -92,5 +92,20 @@ describe('iD.operationStraighten', function () {
var result = iD.operationStraighten(['n2', 'n7', 'w4', 'w1', 'w3', 'w2'], fakeContext.graph()).available();
expect(result).to.be.ok;
});
it('is not available for nodes not on selected ways', function () {
var result = iD.operationStraighten(['w5', 'n4', 'n11'], fakeContext.graph()).available();
expect(result).to.be.not.ok;
});
it('is not available for one selected node', function () {
var result = iD.operationStraighten(['w5', 'n9'], fakeContext.graph()).available();
expect(result).to.be.not.ok;
});
it('is not available for more than two selected nodes', function () {
var result = iD.operationStraighten(['w5', 'n9', 'n11', 'n12'], fakeContext.graph()).available();
expect(result).to.be.not.ok;
});
});
});