Simpler space-to-click

This commit is contained in:
Bryan Housel
2016-05-13 18:50:11 -04:00
parent 24dabfd0cb
commit 64b32edd13
2 changed files with 16 additions and 21 deletions
+16 -18
View File
@@ -10,11 +10,20 @@ iD.behavior.Draw = function(context) {
edit = iD.behavior.Edit(context),
closeTolerance = 4,
tolerance = 12,
lastDatum = {};
lastDatum;
function datum() {
if (d3.event.altKey) return {};
else return d3.event.target.__data__ || {};
if (d3.event.type === 'mousemove') {
lastDatum = d3.event.target.__data__;
}
if (d3.event.type === 'keydown') {
return lastDatum || {};
} else {
return d3.event.target.__data__ || {};
}
}
function mousedown() {
@@ -60,8 +69,7 @@ iD.behavior.Draw = function(context) {
}
function mousemove() {
lastDatum = datum();
event.move(lastDatum);
event.move(datum());
}
function click() {
@@ -80,18 +88,9 @@ iD.behavior.Draw = function(context) {
}
function space() {
var d = lastDatum;
if (d.type === 'way') {
var choice = iD.geo.chooseEdge(context.childNodes(d), context.mouse(), context.projection),
edge = [d.nodes[choice.index - 1], d.nodes[choice.index]];
event.spacedownWay(choice.loc, edge);
} else if (d.type === 'node') {
event.spacedownNode(d);
} else {
event.spacedown(context.map().mouseCoordinates());
}
d3.event.preventDefault();
d3.event.stopPropagation();
click();
}
function backspace() {
@@ -122,8 +121,7 @@ iD.behavior.Draw = function(context) {
.on('⌦', del)
.on('⎋', ret)
.on('↩', ret)
.on('space', space)
.on('Alt+space', space);
.on('space', space, false);
selection
.on('mousedown.draw', mousedown)
-3
View File
@@ -55,9 +55,6 @@ iD.behavior.DrawWay = function(context, wayId, index, mode, baseGraph) {
.on('click', drawWay.add)
.on('clickWay', drawWay.addWay)
.on('clickNode', drawWay.addNode)
.on('spacedown', drawWay.add)
.on('spacedownWay', drawWay.addWay)
.on('spacedownNode', drawWay.addNode)
.on('undo', context.undo)
.on('cancel', drawWay.cancel)
.on('finish', drawWay.finish);