Smarter revert of new entities, more tests

re: #2611, #537
This commit is contained in:
Bryan Housel
2015-04-29 22:47:07 -04:00
parent ca02cf4b96
commit 7adb0ddbfb
3 changed files with 233 additions and 20 deletions
+24 -4
View File
@@ -4,11 +4,31 @@ iD.actions.Revert = function(id) {
var entity = graph.hasEntity(id),
base = graph.base().entities[id];
if (entity && !base) {
return iD.actions.DeleteMultiple([id])(graph);
} else {
return graph.revert(id);
if (entity && !base) { // entity will be removed..
if (entity.type === 'node') {
graph.parentWays(entity)
.forEach(function(parent) {
parent = parent.removeNode(id);
graph = graph.replace(parent);
if (parent.isDegenerate()) {
graph = iD.actions.DeleteWay(parent.id)(graph);
}
});
}
graph.parentRelations(entity)
.forEach(function(parent) {
parent = parent.removeMembersWithID(id);
graph = graph.replace(parent);
if (parent.isDegenerate()) {
graph = iD.actions.DeleteRelation(parent.id)(graph);
}
});
}
return graph.revert(id);
};
return action;