Shift-selection

This commit is contained in:
John Firebaugh
2013-02-01 14:30:46 -05:00
parent ae8891c485
commit 3da0e70c0f
5 changed files with 70 additions and 2 deletions
+6 -2
View File
@@ -2,8 +2,12 @@ iD.behavior.Select = function(context) {
function click() {
var datum = d3.select(d3.event.target).datum();
if (datum instanceof iD.Entity) {
context.enter(iD.modes.Select(context, [datum.id]));
} else {
if (d3.event.shiftKey) {
context.enter(iD.modes.Select(context, context.selection().concat([datum.id])));
} else {
context.enter(iD.modes.Select(context, [datum.id]));
}
} else if (!d3.event.shiftKey) {
context.enter(iD.modes.Browse(context));
}
}
+8
View File
@@ -56,6 +56,14 @@ window.iD = function () {
return mode;
};
context.selection = function() {
if (mode.id === 'select') {
return mode.selection();
} else {
return [];
}
};
/* Behaviors */
context.install = function(behavior) {
context.surface().call(behavior);
+1
View File
@@ -185,6 +185,7 @@
<script src="spec/behavior/hash.js"></script>
<script src="spec/behavior/hover.js"></script>
<script src="spec/behavior/select.js"></script>
<script src="spec/modes/add_point.js"></script>
+1
View File
@@ -80,6 +80,7 @@
<script src="spec/behavior/hash.js"></script>
<script src="spec/behavior/hover.js"></script>
<script src="spec/behavior/select.js"></script>
<script src="spec/modes/add_point.js"></script>
+54
View File
@@ -0,0 +1,54 @@
describe("iD.behavior.Select", function() {
var a, b, context, behavior, container;
beforeEach(function() {
container = d3.select('body').append('div');
context = iD().container(container);
a = iD.Node({loc: [0, 0]});
b = iD.Node({loc: [0, 0]});
context.perform(iD.actions.AddEntity(a), iD.actions.AddEntity(b));
container.call(context.map())
.append('div')
.attr('class', 'inspector-wrap');
context.surface().selectAll('circle')
.data([a, b])
.enter().append('circle')
.attr('class', function(d) { return d.id; });
behavior = iD.behavior.Select(context);
context.install(behavior);
});
afterEach(function() {
context.uninstall(behavior);
container.remove();
});
specify("click on entity selects the entity", function() {
happen.click(context.surface().select('.' + a.id).node());
expect(context.selection()).to.eql([a.id]);
});
specify("click on empty space clears the selection", function() {
context.enter(iD.modes.Select(context, [a.id]));
happen.click(context.surface().node());
expect(context.selection()).to.eql([]);
});
specify("shift-click on entity adds the entity to the selection", function() {
context.enter(iD.modes.Select(context, [a.id]));
happen.click(context.surface().select('.' + b.id).node(), {shiftKey: true});
expect(context.selection()).to.eql([a.id, b.id]);
});
specify("shift-click on empty space leaves the selection unchanged", function() {
context.enter(iD.modes.Select(context, [a.id]));
happen.click(context.surface().node(), {shiftKey: true});
expect(context.selection()).to.eql([a.id]);
});
});