Reintroduce keybindings for deleting features

This commit is contained in:
Tom MacWright
2012-12-04 16:26:00 -05:00
parent 4978cd0c12
commit ddbf50345d
3 changed files with 30 additions and 19 deletions

View File

@@ -28,9 +28,7 @@ window.iD = function(container) {
var buttons = bar.selectAll('button.add-button')
.data([iD.modes.AddPlace, iD.modes.AddRoad, iD.modes.AddArea])
.enter().append('button')
.attr('class', function(d) {
return 'add-button ' + d.id;
})
.attr('class', 'add-button')
.text(function (mode) { return mode.title; })
.on('click', function (mode) { controller.enter(mode); });
@@ -155,6 +153,8 @@ window.iD = function(container) {
if (mods === '⌘') history.undo();
});
d3.select(document).call(keybinding);
map.keybinding(keybinding);
var hash = iD.Hash().map(map);
if (!hash.hadHash) {

View File

@@ -5,6 +5,7 @@ iD.Map = function() {
inspector = iD.Inspector(),
selection = null,
translateStart,
keybinding,
apiTilesLoaded = {},
projection = d3.geo.mercator(),
zoom = d3.behavior.zoom()
@@ -334,6 +335,18 @@ iD.Map = function() {
function nameHoverOut() { d3.select('.messages').text(''); }
function selectClick() {
var entity = d3.select(d3.event.target).data();
if (entity) entity = entity[0];
if (!entity || selection === entity.id || (entity.tags && entity.tags.elastic)) return;
if (entity.type === 'way') d3.select(d3.event.target).call(waydragbehavior);
map.selectEntity(entity);
keybinding.on('⌫.deletefeature', function(e) {
removeEntity(entity);
e.preventDefault();
});
}
function deselectClick() {
var hadSelection = !!selection;
if (hadSelection) {
@@ -345,17 +358,10 @@ iD.Map = function() {
redraw();
hideInspector();
}
keybinding.on('⌫.deletefeature', null);
selection = null;
}
function selectClick() {
var entity = d3.select(d3.event.target).data();
if (entity) entity = entity[0];
if (!entity || selection === entity.id || (entity.tags && entity.tags.elastic)) return;
if (entity.type === 'way') d3.select(d3.event.target).call(waydragbehavior);
map.selectEntity(entity);
}
function removeEntity(entity) {
// Remove this node from any ways that is a member of
history.graph().parents(entity.id)
@@ -364,6 +370,7 @@ iD.Map = function() {
parent.nodes = _.without(parent.nodes, entity.id);
history.perform(iD.actions.removeWayNode(parent, entity));
});
deselectClick();
history.perform(iD.actions.remove(entity));
}
@@ -496,6 +503,12 @@ iD.Map = function() {
return map;
};
map.keybinding = function (_) {
if (!arguments.length) return keybinding;
keybinding = _;
return map;
};
map.selectEntity = function(entity) {
selection = entity.id;
d3.select('.inspector-wrap')

View File

@@ -1,4 +1,6 @@
d3.keybinding = function() {
// via https://github.com/keithamus/jwerty/
// and https://github.com/madrobby/keymaster
var _keys = {
// MOD aka toggleable keys
mods: {
@@ -11,7 +13,6 @@ d3.keybinding = function() {
// META, on Mac: ⌘ (CMD), on Windows (Win), on Linux (Super)
'⌘': 91
},
// Normal keys
keys: {
// Backspace key, on Mac: ⌫ (Backspace)
@@ -40,7 +41,6 @@ d3.keybinding = function() {
ins: 45, insert: 45,
// Delete key, on Mac: ⌫ (Delete)
del: 46, 'delete': 46,
// Left Arrow Key, or ←
'←': 37, left: 37, 'arrow-left': 37,
// Up Arrow Key, or ↑
@@ -49,7 +49,6 @@ d3.keybinding = function() {
'→': 39, right: 39, 'arrow-right': 39,
// Up Arrow Key, or ↓
'↓': 40, down: 40, 'arrow-down': 40,
// odities, printing characters that come out wrong:
// Num-Multiply, or *
'*': 106, star: 106, asterisk: 106, multiply: 106,
@@ -96,13 +95,12 @@ d3.keybinding = function() {
var pairs = d3.entries(_keys.keys),
key_shortcuts = pairs.map(function(d) {
return d.key;
});
var mods = d3.entries(_keys.mods),
}),
mods = d3.entries(_keys.mods),
mod_shortcuts = mods.map(function(d) {
return d.key;
});
var event = d3.dispatch.apply(d3, key_shortcuts),
}),
event = d3.dispatch.apply(d3, key_shortcuts),
modifiers = [];
function keydown() {