mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-23 08:39:56 +02:00
Use context.keybinding for keybindings that don't change
(closes #5487)
This commit is contained in:
@@ -9,26 +9,26 @@ export function behaviorAddWay(context) {
|
||||
var dispatch = d3_dispatch('start', 'startFromWay', 'startFromNode');
|
||||
var draw = behaviorDraw(context);
|
||||
|
||||
var addWay = function(surface) {
|
||||
function behavior(surface) {
|
||||
draw.on('click', function() { dispatch.apply('start', this, arguments); })
|
||||
.on('clickWay', function() { dispatch.apply('startFromWay', this, arguments); })
|
||||
.on('clickNode', function() { dispatch.apply('startFromNode', this, arguments); })
|
||||
.on('cancel', addWay.cancel)
|
||||
.on('finish', addWay.cancel);
|
||||
.on('cancel', behavior.cancel)
|
||||
.on('finish', behavior.cancel);
|
||||
|
||||
context.map()
|
||||
.dblclickEnable(false);
|
||||
|
||||
surface.call(draw);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
addWay.off = function(surface) {
|
||||
behavior.off = function(surface) {
|
||||
surface.call(draw.off);
|
||||
};
|
||||
|
||||
|
||||
addWay.cancel = function() {
|
||||
behavior.cancel = function() {
|
||||
window.setTimeout(function() {
|
||||
context.map().dblclickEnable(true);
|
||||
}, 1000);
|
||||
@@ -37,11 +37,11 @@ export function behaviorAddWay(context) {
|
||||
};
|
||||
|
||||
|
||||
addWay.tail = function(text) {
|
||||
behavior.tail = function(text) {
|
||||
draw.tail(text);
|
||||
return addWay;
|
||||
return behavior;
|
||||
};
|
||||
|
||||
|
||||
return utilRebind(addWay, dispatch, 'on');
|
||||
return utilRebind(behavior, dispatch, 'on');
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ export function behaviorBreathe() {
|
||||
}
|
||||
|
||||
|
||||
var breathe = function(surface) {
|
||||
function behavior(surface) {
|
||||
_done = false;
|
||||
_timer = d3_timer(function() {
|
||||
// wait for elements to actually become selected
|
||||
@@ -148,10 +148,10 @@ export function behaviorBreathe() {
|
||||
_timer.stop();
|
||||
return true;
|
||||
}, 20);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
breathe.off = function() {
|
||||
behavior.off = function() {
|
||||
_done = true;
|
||||
if (_timer) {
|
||||
_timer.stop();
|
||||
@@ -162,5 +162,5 @@ export function behaviorBreathe() {
|
||||
};
|
||||
|
||||
|
||||
return breathe;
|
||||
return behavior;
|
||||
}
|
||||
|
||||
+15
-20
@@ -2,18 +2,11 @@ import _extend from 'lodash-es/extend';
|
||||
import _groupBy from 'lodash-es/groupBy';
|
||||
import _map from 'lodash-es/map';
|
||||
|
||||
import {
|
||||
event as d3_event,
|
||||
select as d3_select
|
||||
} from 'd3-selection';
|
||||
|
||||
import { utilKeybinding } from '../util';
|
||||
import { event as d3_event } from 'd3-selection';
|
||||
import { uiCmd } from '../ui';
|
||||
|
||||
|
||||
export function behaviorCopy(context) {
|
||||
var keybinding = utilKeybinding('copy');
|
||||
|
||||
|
||||
function groupEntities(ids, graph) {
|
||||
var entities = ids.map(function (id) { return graph.entity(id); });
|
||||
@@ -47,8 +40,15 @@ export function behaviorCopy(context) {
|
||||
}
|
||||
|
||||
|
||||
function getSelectionText() {
|
||||
return window.getSelection().toString();
|
||||
}
|
||||
|
||||
|
||||
function doCopy() {
|
||||
if (!getSelectionText()) d3_event.preventDefault();
|
||||
if (!getSelectionText()) {
|
||||
d3_event.preventDefault();
|
||||
}
|
||||
|
||||
var graph = context.graph();
|
||||
var selected = groupEntities(context.selectedIDs(), graph);
|
||||
@@ -82,20 +82,15 @@ export function behaviorCopy(context) {
|
||||
}
|
||||
|
||||
|
||||
function copy() {
|
||||
keybinding.on(uiCmd('⌘C'), doCopy);
|
||||
d3_select(document).call(keybinding);
|
||||
return copy;
|
||||
function behavior() {
|
||||
context.keybinding().on(uiCmd('⌘C'), doCopy);
|
||||
return behavior;
|
||||
}
|
||||
|
||||
function getSelectionText() {
|
||||
return window.getSelection().toString();
|
||||
}
|
||||
|
||||
copy.off = function() {
|
||||
d3_select(document).call(keybinding.off);
|
||||
behavior.off = function() {
|
||||
context.keybinding().off(uiCmd('⌘C'));
|
||||
};
|
||||
|
||||
|
||||
return copy;
|
||||
return behavior;
|
||||
}
|
||||
|
||||
+15
-20
@@ -10,13 +10,8 @@ import {
|
||||
} from 'd3-selection';
|
||||
|
||||
import { osmNote } from '../osm';
|
||||
|
||||
import { utilRebind } from '../util/rebind';
|
||||
|
||||
import {
|
||||
utilPrefixCSSProperty,
|
||||
utilPrefixDOMProperty
|
||||
} from '../util';
|
||||
import { utilPrefixCSSProperty, utilPrefixDOMProperty } from '../util';
|
||||
|
||||
|
||||
/*
|
||||
@@ -62,7 +57,7 @@ export function behaviorDrag() {
|
||||
|
||||
function eventOf(thiz, argumentz) {
|
||||
return function(e1) {
|
||||
e1.target = drag;
|
||||
e1.target = behavior;
|
||||
d3_customEvent(e1, dispatch.apply, dispatch, [e1.type, thiz, argumentz]);
|
||||
};
|
||||
}
|
||||
@@ -154,7 +149,7 @@ export function behaviorDrag() {
|
||||
}
|
||||
|
||||
|
||||
function drag(selection) {
|
||||
function behavior(selection) {
|
||||
var matchesSelector = utilPrefixDOMProperty('matchesSelector');
|
||||
var delegate = dragstart;
|
||||
|
||||
@@ -181,49 +176,49 @@ export function behaviorDrag() {
|
||||
}
|
||||
|
||||
|
||||
drag.off = function(selection) {
|
||||
behavior.off = function(selection) {
|
||||
selection
|
||||
.on('mousedown.drag' + _selector, null)
|
||||
.on('touchstart.drag' + _selector, null);
|
||||
};
|
||||
|
||||
|
||||
drag.selector = function(_) {
|
||||
behavior.selector = function(_) {
|
||||
if (!arguments.length) return _selector;
|
||||
_selector = _;
|
||||
return drag;
|
||||
return behavior;
|
||||
};
|
||||
|
||||
|
||||
drag.origin = function (_) {
|
||||
behavior.origin = function(_) {
|
||||
if (!arguments.length) return _origin;
|
||||
_origin = _;
|
||||
return drag;
|
||||
return behavior;
|
||||
};
|
||||
|
||||
|
||||
drag.cancel = function() {
|
||||
behavior.cancel = function() {
|
||||
d3_select(window)
|
||||
.on('mousemove.drag', null)
|
||||
.on('mouseup.drag', null);
|
||||
return drag;
|
||||
return behavior;
|
||||
};
|
||||
|
||||
|
||||
drag.target = function() {
|
||||
behavior.target = function() {
|
||||
if (!arguments.length) return _target;
|
||||
_target = arguments[0];
|
||||
_event = eventOf(_target, Array.prototype.slice.call(arguments, 1));
|
||||
return drag;
|
||||
return behavior;
|
||||
};
|
||||
|
||||
|
||||
drag.surface = function() {
|
||||
behavior.surface = function() {
|
||||
if (!arguments.length) return _surface;
|
||||
_surface = arguments[0];
|
||||
return drag;
|
||||
return behavior;
|
||||
};
|
||||
|
||||
|
||||
return utilRebind(drag, dispatch, 'on');
|
||||
return utilRebind(behavior, dispatch, 'on');
|
||||
}
|
||||
|
||||
@@ -190,7 +190,7 @@ export function behaviorDraw(context) {
|
||||
}
|
||||
|
||||
|
||||
function draw(selection) {
|
||||
function behavior(selection) {
|
||||
context.install(hover);
|
||||
context.install(edit);
|
||||
|
||||
@@ -215,11 +215,11 @@ export function behaviorDraw(context) {
|
||||
d3_select(document)
|
||||
.call(keybinding);
|
||||
|
||||
return draw;
|
||||
return behavior;
|
||||
}
|
||||
|
||||
|
||||
draw.off = function(selection) {
|
||||
behavior.off = function(selection) {
|
||||
context.ui().sidebar.hover.cancel();
|
||||
context.uninstall(hover);
|
||||
context.uninstall(edit);
|
||||
@@ -240,15 +240,15 @@ export function behaviorDraw(context) {
|
||||
// note: keyup.space-block, click.draw-block should remain
|
||||
|
||||
d3_select(document)
|
||||
.call(keybinding.off);
|
||||
.call(keybinding.unbind);
|
||||
};
|
||||
|
||||
|
||||
draw.tail = function(_) {
|
||||
behavior.tail = function(_) {
|
||||
tail.text(_);
|
||||
return draw;
|
||||
return behavior;
|
||||
};
|
||||
|
||||
|
||||
return utilRebind(draw, dispatch, 'on');
|
||||
return utilRebind(behavior, dispatch, 'on');
|
||||
}
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
export function behaviorEdit(context) {
|
||||
|
||||
function edit() {
|
||||
function behavior() {
|
||||
context.map()
|
||||
.minzoom(context.minEditableZoom());
|
||||
}
|
||||
|
||||
|
||||
edit.off = function() {
|
||||
behavior.off = function() {
|
||||
context.map()
|
||||
.minzoom(0);
|
||||
};
|
||||
|
||||
|
||||
return edit;
|
||||
return behavior;
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ export function behaviorHash(context) {
|
||||
}
|
||||
|
||||
|
||||
function hash() {
|
||||
function behavior() {
|
||||
context.map()
|
||||
.on('move.hash', throttledUpdate);
|
||||
|
||||
@@ -97,7 +97,6 @@ export function behaviorHash(context) {
|
||||
.on('hashchange.hash', hashchange);
|
||||
|
||||
if (window.location.hash) {
|
||||
|
||||
var q = utilStringQs(window.location.hash.substring(1));
|
||||
|
||||
if (q.id) {
|
||||
@@ -119,19 +118,19 @@ export function behaviorHash(context) {
|
||||
}
|
||||
|
||||
if (q.walkthrough === 'true') {
|
||||
hash.startWalkthrough = true;
|
||||
behavior.startWalkthrough = true;
|
||||
}
|
||||
|
||||
hashchange();
|
||||
|
||||
if (q.map) {
|
||||
hash.hadHash = true;
|
||||
behavior.hadHash = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
hash.off = function() {
|
||||
behavior.off = function() {
|
||||
throttledUpdate.cancel();
|
||||
|
||||
context.map()
|
||||
@@ -147,5 +146,5 @@ export function behaviorHash(context) {
|
||||
};
|
||||
|
||||
|
||||
return hash;
|
||||
return behavior;
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ export function behaviorHover(context) {
|
||||
}
|
||||
|
||||
|
||||
var hover = function(selection) {
|
||||
function behavior(selection) {
|
||||
_selection = selection;
|
||||
_newId = null;
|
||||
|
||||
@@ -150,10 +150,10 @@ export function behaviorHover(context) {
|
||||
dispatch.call('hover', this, null);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
hover.off = function(selection) {
|
||||
behavior.off = function(selection) {
|
||||
selection.selectAll('.hover')
|
||||
.classed('hover', false);
|
||||
selection.selectAll('.hover-suppressed')
|
||||
@@ -172,12 +172,12 @@ export function behaviorHover(context) {
|
||||
};
|
||||
|
||||
|
||||
hover.altDisables = function(_) {
|
||||
behavior.altDisables = function(val) {
|
||||
if (!arguments.length) return _altDisables;
|
||||
_altDisables = _;
|
||||
return hover;
|
||||
_altDisables = val;
|
||||
return behavior;
|
||||
};
|
||||
|
||||
|
||||
return utilRebind(hover, dispatch, 'on');
|
||||
return utilRebind(behavior, dispatch, 'on');
|
||||
}
|
||||
|
||||
@@ -1,57 +1,51 @@
|
||||
import {
|
||||
event as d3_event,
|
||||
select as d3_select
|
||||
} from 'd3-selection';
|
||||
|
||||
import { event as d3_event } from 'd3-selection';
|
||||
import { uiFlash } from '../ui';
|
||||
import { utilKeybinding } from '../util';
|
||||
|
||||
|
||||
/* Creates a keybinding behavior for an operation */
|
||||
export function behaviorOperation() {
|
||||
var keybinding;
|
||||
export function behaviorOperation(context) {
|
||||
var _operation;
|
||||
|
||||
var behavior = function () {
|
||||
function keypress() {
|
||||
d3_event.preventDefault();
|
||||
var disabled = _operation.disabled();
|
||||
var flash;
|
||||
|
||||
if (disabled) {
|
||||
flash = uiFlash()
|
||||
.duration(4000)
|
||||
.iconName('#iD-operation-' + _operation.id)
|
||||
.iconClass('operation disabled')
|
||||
.text(_operation.tooltip);
|
||||
|
||||
flash();
|
||||
|
||||
} else {
|
||||
flash = uiFlash()
|
||||
.duration(2000)
|
||||
.iconName('#iD-operation-' + _operation.id)
|
||||
.iconClass('operation')
|
||||
.text(_operation.annotation() || _operation.title);
|
||||
|
||||
flash();
|
||||
_operation();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function behavior() {
|
||||
if (_operation && _operation.available()) {
|
||||
keybinding = utilKeybinding('behavior.key.' + _operation.id);
|
||||
keybinding.on(_operation.keys, function() {
|
||||
d3_event.preventDefault();
|
||||
var disabled = _operation.disabled();
|
||||
var flash;
|
||||
|
||||
if (disabled) {
|
||||
flash = uiFlash()
|
||||
.duration(4000)
|
||||
.iconName('#iD-operation-' + _operation.id)
|
||||
.iconClass('operation disabled')
|
||||
.text(_operation.tooltip);
|
||||
|
||||
flash();
|
||||
|
||||
} else {
|
||||
flash = uiFlash()
|
||||
.duration(2000)
|
||||
.iconName('#iD-operation-' + _operation.id)
|
||||
.iconClass('operation')
|
||||
.text(_operation.annotation() || _operation.title);
|
||||
|
||||
flash();
|
||||
_operation();
|
||||
}
|
||||
});
|
||||
|
||||
d3_select(document).call(keybinding);
|
||||
context.keybinding()
|
||||
.on(_operation.keys, keypress);
|
||||
}
|
||||
|
||||
return behavior;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
behavior.off = function() {
|
||||
if (keybinding) {
|
||||
d3_select(document).call(keybinding.off);
|
||||
}
|
||||
context.keybinding()
|
||||
.off(_operation.keys);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1,30 +1,15 @@
|
||||
import _invert from 'lodash-es/invert';
|
||||
import _mapValues from 'lodash-es/mapValues';
|
||||
|
||||
import {
|
||||
event as d3_event,
|
||||
select as d3_select
|
||||
} from 'd3-selection';
|
||||
|
||||
import {
|
||||
actionCopyEntities,
|
||||
actionMove
|
||||
} from '../actions';
|
||||
|
||||
import {
|
||||
geoExtent,
|
||||
geoPointInPolygon,
|
||||
geoVecSubtract
|
||||
} from '../geo';
|
||||
import { event as d3_event } from 'd3-selection';
|
||||
|
||||
import { actionCopyEntities, actionMove } from '../actions';
|
||||
import { geoExtent, geoPointInPolygon, geoVecSubtract } from '../geo';
|
||||
import { modeMove } from '../modes';
|
||||
import { uiCmd } from '../ui';
|
||||
import { utilKeybinding } from '../util';
|
||||
|
||||
|
||||
export function behaviorPaste(context) {
|
||||
var keybinding = utilKeybinding('paste');
|
||||
|
||||
|
||||
function doPaste() {
|
||||
d3_event.preventDefault();
|
||||
@@ -78,17 +63,16 @@ export function behaviorPaste(context) {
|
||||
}
|
||||
|
||||
|
||||
function paste() {
|
||||
keybinding.on(uiCmd('⌘V'), doPaste);
|
||||
d3_select(document).call(keybinding);
|
||||
return paste;
|
||||
function behavior() {
|
||||
context.keybinding().on(uiCmd('⌘V'), doPaste);
|
||||
return behavior;
|
||||
}
|
||||
|
||||
|
||||
paste.off = function() {
|
||||
d3_select(document).call(keybinding.off);
|
||||
behavior.off = function() {
|
||||
context.keybinding().off(uiCmd('⌘V'));
|
||||
};
|
||||
|
||||
|
||||
return paste;
|
||||
return behavior;
|
||||
}
|
||||
|
||||
@@ -180,7 +180,7 @@ export function behaviorSelect(context) {
|
||||
}
|
||||
|
||||
|
||||
var behavior = function(selection) {
|
||||
function behavior(selection) {
|
||||
lastMouse = null;
|
||||
suppressMenu = true;
|
||||
p1 = null;
|
||||
@@ -208,7 +208,7 @@ export function behaviorSelect(context) {
|
||||
context.surface()
|
||||
.classed('behavior-multiselect', true);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
behavior.off = function(selection) {
|
||||
|
||||
@@ -15,7 +15,7 @@ export function behaviorTail() {
|
||||
var _text;
|
||||
|
||||
|
||||
function tail(selection) {
|
||||
function behavior(selection) {
|
||||
if (!_text) return;
|
||||
|
||||
d3_select(window)
|
||||
@@ -71,7 +71,7 @@ export function behaviorTail() {
|
||||
}
|
||||
|
||||
|
||||
tail.off = function(selection) {
|
||||
behavior.off = function(selection) {
|
||||
if (!_text) return;
|
||||
|
||||
container
|
||||
@@ -88,12 +88,12 @@ export function behaviorTail() {
|
||||
};
|
||||
|
||||
|
||||
tail.text = function(val) {
|
||||
behavior.text = function(val) {
|
||||
if (!arguments.length) return _text;
|
||||
_text = val;
|
||||
return tail;
|
||||
return behavior;
|
||||
};
|
||||
|
||||
|
||||
return tail;
|
||||
return behavior;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user