Don't enter iD.modeSelect without valid entities in selectedIDs

This commit is contained in:
Bryan Housel
2016-12-09 11:32:14 -05:00
parent a3de3534c3
commit 8a66b3d892
3 changed files with 39 additions and 5 deletions

View File

@@ -152,7 +152,9 @@ export function behaviorBreathe() {
breathe.off = function() {
done = true;
timer.stop();
if (timer) {
timer.stop();
}
selected
.interrupt()
.call(reset);

View File

@@ -71,6 +71,23 @@ export function modeSelect(context, selectedIDs) {
}
function checkSelectedIDs() {
var ids = [];
if (Array.isArray(selectedIDs)) {
ids = selectedIDs.filter(function(id) {
return context.hasEntity(id);
});
}
if (ids.length) {
selectedIDs = ids;
} else {
context.enter(modeBrowse(context));
}
return !!ids.length;
}
// find the common parent ways for nextVertex, previousVertex
function commonParents() {
var graph = context.graph(),
@@ -171,6 +188,8 @@ export function modeSelect(context, selectedIDs) {
mode.reselect = function() {
if (!checkSelectedIDs()) return;
var surfaceNode = context.surface().node();
if (surfaceNode.focus) { // FF doesn't support it
surfaceNode.focus();
@@ -206,10 +225,7 @@ export function modeSelect(context, selectedIDs) {
function update() {
closeMenu();
if (_.some(selectedIDs, function(id) { return !context.hasEntity(id); })) {
// Exit mode if selected entity gets undone
context.enter(modeBrowse(context));
}
checkSelectedIDs();
}
@@ -236,6 +252,8 @@ export function modeSelect(context, selectedIDs) {
function selectElements(drawn) {
if (!checkSelectedIDs()) return;
var surface = context.surface(),
entity = singular();
@@ -372,6 +390,8 @@ export function modeSelect(context, selectedIDs) {
}
if (!checkSelectedIDs()) return;
behaviors.forEach(function(behavior) {
context.install(behavior);
});

View File

@@ -31,6 +31,18 @@ describe('iD.behaviorSelect', function() {
container.remove();
});
specify('refuse to enter select mode with no ids', function() {
context.enter(iD.modeSelect(context, []));
expect(context.mode().id, 'empty array').to.eql('browse');
context.enter(iD.modeSelect(context, undefined));
expect(context.mode().id, 'undefined').to.eql('browse');
});
specify('refuse to enter select mode with nonexistent ids', function() {
context.enter(iD.modeSelect(context, ['w-1']));
expect(context.mode().id).to.eql('browse');
});
specify('click on entity selects the entity', function() {
happen.click(context.surface().selectAll('.' + a.id).node());
expect(context.selectedIDs()).to.eql([a.id]);