selection -> selectedIDs

Overloading "selection" is a bad idea.
This commit is contained in:
John Firebaugh
2013-06-03 15:47:13 -07:00
parent eebd9aa030
commit a84a3364cc
23 changed files with 82 additions and 82 deletions

View File

@@ -22,19 +22,19 @@ iD.behavior.Select = function(context) {
} else if (!d3.event.shiftKey && !lasso) {
// Avoid re-entering Select mode with same entity.
if (context.selection().length !== 1 || context.selection()[0] !== datum.id) {
if (context.selectedIDs().length !== 1 || context.selectedIDs()[0] !== datum.id) {
context.enter(iD.modes.Select(context, [datum.id]));
} else {
context.mode().reselect();
}
} else if (context.selection().indexOf(datum.id) >= 0) {
var selection = _.without(context.selection(), datum.id);
context.enter(selection.length ?
iD.modes.Select(context, selection) :
} else if (context.selectedIDs().indexOf(datum.id) >= 0) {
var selectedIDs = _.without(context.selectedIDs(), datum.id);
context.enter(selectedIDs.length ?
iD.modes.Select(context, selectedIDs) :
iD.modes.Browse(context));
} else {
context.enter(iD.modes.Select(context, context.selection().concat([datum.id])));
context.enter(iD.modes.Select(context, context.selectedIDs().concat([datum.id])));
}
}

View File

@@ -100,7 +100,7 @@ window.iD = function () {
/* Modes */
context.enter = function(newMode) {
var s0 = context.selection();
var s0 = context.selectedIDs();
if (mode) {
mode.exit();
@@ -111,7 +111,7 @@ window.iD = function () {
mode.enter();
dispatch.enter(mode);
var s1 = context.selection();
var s1 = context.selectedIDs();
dispatch.select(s1, s0);
};
@@ -119,9 +119,9 @@ window.iD = function () {
return mode;
};
context.selection = function() {
if (mode && mode.selection) {
return mode.selection();
context.selectedIDs = function() {
if (mode && mode.selectedIDs) {
return mode.selectedIDs();
} else {
return [];
}

View File

@@ -8,7 +8,7 @@ iD.modes.DragNode = function(context) {
activeIDs,
wasMidpoint,
cancelled,
selection = [],
selectedIDs = [],
hover = iD.behavior.Hover(context).altDisables(true);
function edge(point, size) {
@@ -136,7 +136,7 @@ iD.modes.DragNode = function(context) {
moveAnnotation(entity));
}
var reselection = selection.filter(function(id) {
var reselection = selectedIDs.filter(function(id) {
return context.graph().hasEntity(id);
});
@@ -195,9 +195,9 @@ iD.modes.DragNode = function(context) {
stopNudge();
};
mode.selection = function(_) {
if (!arguments.length) return selection;
selection = _;
mode.selectedIDs = function(_) {
if (!arguments.length) return selectedIDs;
selectedIDs = _;
return mode;
};

View File

@@ -31,7 +31,7 @@ iD.modes.DrawArea = function(context, wayId, baseGraph) {
context.uninstall(behavior);
};
mode.selection = function() {
mode.selectedIDs = function() {
return [wayId];
};

View File

@@ -31,7 +31,7 @@ iD.modes.DrawLine = function(context, wayId, direction, baseGraph) {
context.uninstall(behavior);
};
mode.selection = function() {
mode.selectedIDs = function() {
return [wayId];
};

View File

@@ -1,4 +1,4 @@
iD.modes.Select = function(context, selection) {
iD.modes.Select = function(context, selectedIDs) {
var mode = {
id: 'select',
button: 'browse'
@@ -11,7 +11,7 @@ iD.modes.Select = function(context, selection) {
iD.behavior.Select(context),
iD.behavior.Lasso(context),
iD.modes.DragNode(context)
.selection(selection)
.selectedIDs(selectedIDs)
.behavior],
inspector,
radialMenu,
@@ -22,8 +22,8 @@ iD.modes.Select = function(context, selection) {
.select('.inspector-wrap');
function singular() {
if (selection.length === 1) {
return context.entity(selection[0]);
if (selectedIDs.length === 1) {
return context.entity(selectedIDs[0]);
}
}
@@ -43,8 +43,8 @@ iD.modes.Select = function(context, selection) {
.call(radialMenu);
}
mode.selection = function() {
return selection;
mode.selectedIDs = function() {
return selectedIDs;
};
mode.reselect = function() {
@@ -75,9 +75,9 @@ iD.modes.Select = function(context, selection) {
});
var operations = _.without(d3.values(iD.operations), iD.operations.Delete)
.map(function(o) { return o(selection, context); })
.map(function(o) { return o(selectedIDs, context); })
.filter(function(o) { return o.available(); });
operations.unshift(iD.operations.Delete(selection, context));
operations.unshift(iD.operations.Delete(selectedIDs, context));
keybinding.on('⎋', function() {
context.enter(iD.modes.Browse(context));
@@ -93,7 +93,7 @@ iD.modes.Select = function(context, selection) {
});
});
var notNew = selection.filter(function(id) {
var notNew = selectedIDs.filter(function(id) {
return !context.entity(id).isNew();
});
@@ -111,7 +111,7 @@ iD.modes.Select = function(context, selection) {
function update() {
context.surface().call(radialMenu.close);
if (_.any(selection, function(id) { return !context.hasEntity(id); })) {
if (_.any(selectedIDs, function(id) { return !context.hasEntity(id); })) {
// Exit mode if selected entity gets undone
context.enter(iD.modes.Browse(context));
}
@@ -142,9 +142,9 @@ iD.modes.Select = function(context, selection) {
}
function selected() {
var s = iD.util.entitySelector(selection);
var s = iD.util.entitySelector(selectedIDs);
selection.forEach(function(id) {
selectedIDs.forEach(function(id) {
var entity = context.hasEntity(id);
if (entity && entity.type === 'relation') {
entity.members.forEach(function(member) {

View File

@@ -1,5 +1,5 @@
iD.operations.Circularize = function(selection, context) {
var entityId = selection[0],
iD.operations.Circularize = function(selectedIDs, context) {
var entityId = selectedIDs[0],
geometry = context.geometry(entityId),
action = iD.actions.Circularize(entityId, context.projection);
@@ -9,7 +9,7 @@ iD.operations.Circularize = function(selection, context) {
};
operation.available = function() {
return selection.length === 1 &&
return selectedIDs.length === 1 &&
context.entity(entityId).type === 'way';
};

View File

@@ -1,15 +1,15 @@
iD.operations.Delete = function(selection, context) {
var action = iD.actions.DeleteMultiple(selection);
iD.operations.Delete = function(selectedIDs, context) {
var action = iD.actions.DeleteMultiple(selectedIDs);
var operation = function() {
var annotation,
mode;
if (selection.length > 1) {
annotation = t('operations.delete.annotation.multiple', {n: selection.length});
if (selectedIDs.length > 1) {
annotation = t('operations.delete.annotation.multiple', {n: selectedIDs.length});
mode = iD.modes.Browse(context);
} else {
var id = selection[0],
var id = selectedIDs[0],
entity = context.entity(id),
geometry = context.geometry(id),
parents = context.graph().parentWays(entity),

View File

@@ -1,13 +1,13 @@
iD.operations.Disconnect = function(selection, context) {
var vertices = _.filter(selection, function vertex(entityId) {
iD.operations.Disconnect = function(selectedIDs, context) {
var vertices = _.filter(selectedIDs, function vertex(entityId) {
return context.geometry(entityId) === 'vertex';
});
var entityId = vertices[0],
action = iD.actions.Disconnect(entityId);
if (selection.length > 1) {
action.limitWays(_.without(selection, entityId));
if (selectedIDs.length > 1) {
action.limitWays(_.without(selectedIDs, entityId));
}
var operation = function() {

View File

@@ -1,10 +1,10 @@
iD.operations.Merge = function(selection, context) {
var join = iD.actions.Join(selection),
merge = iD.actions.Merge(selection),
mergePolygon = iD.actions.MergePolygon(selection);
iD.operations.Merge = function(selectedIDs, context) {
var join = iD.actions.Join(selectedIDs),
merge = iD.actions.Merge(selectedIDs),
mergePolygon = iD.actions.MergePolygon(selectedIDs);
var operation = function() {
var annotation = t('operations.merge.annotation', {n: selection.length}),
var annotation = t('operations.merge.annotation', {n: selectedIDs.length}),
action;
if (!join.disabled(context.graph())) {
@@ -20,7 +20,7 @@ iD.operations.Merge = function(selection, context) {
};
operation.available = function() {
return selection.length >= 2;
return selectedIDs.length >= 2;
};
operation.disabled = function() {

View File

@@ -1,15 +1,15 @@
iD.operations.Move = function(selection, context) {
iD.operations.Move = function(selectedIDs, context) {
var operation = function() {
context.enter(iD.modes.Move(context, selection));
context.enter(iD.modes.Move(context, selectedIDs));
};
operation.available = function() {
return selection.length > 1 ||
context.entity(selection[0]).type !== 'node';
return selectedIDs.length > 1 ||
context.entity(selectedIDs[0]).type !== 'node';
};
operation.disabled = function() {
return iD.actions.Move(selection)
return iD.actions.Move(selectedIDs)
.disabled(context.graph());
};

View File

@@ -1,5 +1,5 @@
iD.operations.Orthogonalize = function(selection, context) {
var entityId = selection[0],
iD.operations.Orthogonalize = function(selectedIDs, context) {
var entityId = selectedIDs[0],
action = iD.actions.Orthogonalize(entityId, context.projection);
var operation = function() {
@@ -8,7 +8,7 @@ iD.operations.Orthogonalize = function(selection, context) {
};
operation.available = function() {
return selection.length === 1 &&
return selectedIDs.length === 1 &&
context.entity(entityId).type === 'way' &&
_.uniq(context.entity(entityId).nodes).length > 2;
};

View File

@@ -1,5 +1,5 @@
iD.operations.Reverse = function(selection, context) {
var entityId = selection[0];
iD.operations.Reverse = function(selectedIDs, context) {
var entityId = selectedIDs[0];
var operation = function() {
context.perform(
@@ -8,7 +8,7 @@ iD.operations.Reverse = function(selection, context) {
};
operation.available = function() {
return selection.length === 1 &&
return selectedIDs.length === 1 &&
context.geometry(entityId) === 'line';
};

View File

@@ -1,12 +1,12 @@
iD.operations.Rotate = function(selection, context) {
var entityId = selection[0];
iD.operations.Rotate = function(selectedIDs, context) {
var entityId = selectedIDs[0];
var operation = function() {
context.enter(iD.modes.RotateWay(context, entityId));
};
operation.available = function() {
return selection.length === 1 &&
return selectedIDs.length === 1 &&
context.entity(entityId).type === 'way' &&
context.geometry(entityId) === 'area';
};

View File

@@ -1,13 +1,13 @@
iD.operations.Split = function(selection, context) {
var vertices = _.filter(selection, function vertex(entityId) {
iD.operations.Split = function(selectedIDs, context) {
var vertices = _.filter(selectedIDs, function vertex(entityId) {
return context.geometry(entityId) === 'vertex';
});
var entityId = vertices[0],
action = iD.actions.Split(entityId);
if (selection.length > 1) {
action.limitWays(_.without(selection, entityId));
if (selectedIDs.length > 1) {
action.limitWays(_.without(selectedIDs, entityId));
}
var operation = function() {

View File

@@ -6,7 +6,7 @@ iD.svg.Midpoints = function(projection, context) {
var entity = entities[i];
if (entity.type !== 'way') continue;
if (context.selection().indexOf(entity.id) < 0) continue;
if (context.selectedIDs().indexOf(entity.id) < 0) continue;
var nodes = graph.childNodes(entity);

View File

@@ -108,7 +108,7 @@ iD.svg.Vertices = function(projection, context) {
}
function drawVertices(surface, graph, entities, filter, extent, zoom) {
var selected = siblingAndChildVertices(context.selection(), graph, extent),
var selected = siblingAndChildVertices(context.selectedIDs(), graph, extent),
vertices = [];
for (var i = 0; i < entities.length; i++) {

View File

@@ -64,7 +64,7 @@ iD.ui.intro.line = function(context, reveal) {
var pointBox = iD.ui.intro.pad(context.projection(intersection), 30);
reveal(pointBox, 'intro.lines.restart');
timeout(function() {
context.replace(iD.actions.DeleteMultiple(mode.selection()));
context.replace(iD.actions.DeleteMultiple(mode.selectedIDs()));
step.exit();
step.enter();
}, 3000);

View File

@@ -7,7 +7,7 @@ iD.ui.Sidebar = function(context) {
.attr('class', 'inspector-hidden inspector-wrap fr');
context.on('hover.sidebar', function(entity) {
if (context.selection().length === 1) return;
if (context.selectedIDs().length === 1) return;
if (!current && entity) {
wrap.classed('inspector-hidden', false)
@@ -25,15 +25,15 @@ iD.ui.Sidebar = function(context) {
}
});
context.on('select.sidebar', function(selection) {
if (!current && selection.length === 1) {
context.on('select.sidebar', function(selectedIDs) {
if (!current && selectedIDs.length === 1) {
wrap.classed('inspector-hidden', false)
.classed('inspector-hover', false);
if (inspector.entityID() !== selection[0] || inspector.state() !== 'select') {
if (inspector.entityID() !== selectedIDs[0] || inspector.state() !== 'select') {
inspector
.state('select')
.entityID(selection[0]);
.entityID(selectedIDs[0]);
wrap.call(inspector);
}

View File

@@ -103,7 +103,7 @@
return 'img/' + _;
};
context.selection = function() {
context.selectedIDs = function() {
return [];
};

View File

@@ -34,7 +34,7 @@ describe("iD.behavior.Select", function() {
specify("click on entity selects the entity", function() {
happen.click(context.surface().select('.' + a.id).node());
expect(context.selection()).to.eql([a.id]);
expect(context.selectedIDs()).to.eql([a.id]);
});
specify("click on empty space clears the selection", function() {
@@ -46,13 +46,13 @@ describe("iD.behavior.Select", function() {
specify("shift-click on unselected entity adds it 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]);
expect(context.selectedIDs()).to.eql([a.id, b.id]);
});
specify("shift-click on selected entity removes it from the selection", function() {
context.enter(iD.modes.Select(context, [a.id, b.id]));
happen.click(context.surface().select('.' + b.id).node(), {shiftKey: true});
expect(context.selection()).to.eql([a.id]);
expect(context.selectedIDs()).to.eql([a.id]);
});
specify("shift-click on last selected entity clears the selection", function() {
@@ -64,6 +64,6 @@ describe("iD.behavior.Select", function() {
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]);
expect(context.selectedIDs()).to.eql([a.id]);
});
});

View File

@@ -27,7 +27,7 @@ describe("iD.modes.AddPoint", function() {
happen.mousedown(context.surface().node(), {});
happen.mouseup(window, {});
expect(context.mode().id).to.equal('select');
expect(context.mode().selection()).to.eql([context.changes().created[0].id]);
expect(context.mode().selectedIDs()).to.eql([context.changes().created[0].id]);
context.mode().exit();
});
});

View File

@@ -17,7 +17,7 @@ describe("iD.svg.Midpoints", function () {
graph = iD.Graph([a, b, line]),
extent = iD.geo.Extent([0, 0], [100, 100]);
context.selection = function() { return [line.id]; };
context.selectedIDs = function() { return [line.id]; };
surface.call(iD.svg.Midpoints(projection, context), graph, [line], filter, extent);
expect(surface.select('.midpoint').datum().loc).to.eql([25, 0]);
@@ -30,7 +30,7 @@ describe("iD.svg.Midpoints", function () {
graph = iD.Graph([a, b, line]),
extent = iD.geo.Extent([0, 0], [100, 100]);
context.selection = function() { return [line.id]; };
context.selectedIDs = function() { return [line.id]; };
surface.call(iD.svg.Midpoints(projection, context), graph, [line], filter, extent);
expect(surface.selectAll('.midpoint')[0]).to.have.length(0);