mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-14 13:18:15 +02:00
Enforce either 0 or 2 selected vertices
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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 ||
|
||||
|
||||
@@ -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;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user