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
+24 -4
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);
});