mirror of
https://github.com/FoggedLens/iD.git
synced 2026-06-05 14:38:05 +02:00
Unique values for key codes moved to utilKeybinding, uiShortcuts
This lets us supply lists of keys which might contain duplicates, but will be
made unique. For example: [t('sidebar.key'), '`', '²']
'sidebar.key' may be one of the other choices, but will be deduplicated.
This commit is contained in:
+1
-4
@@ -1,5 +1,3 @@
|
||||
import _uniq from 'lodash-es/uniq';
|
||||
|
||||
import {
|
||||
event as d3_event,
|
||||
select as d3_select
|
||||
@@ -300,10 +298,9 @@ export function uiInit(context) {
|
||||
|
||||
|
||||
var panPixels = 80;
|
||||
var sidebarKeys = _uniq([t('sidebar.key'), '`', '²']); // #5663
|
||||
context.keybinding()
|
||||
.on('⌫', function() { d3_event.preventDefault(); })
|
||||
.on(sidebarKeys, ui.sidebar.toggle)
|
||||
.on([t('sidebar.key'), '`', '²'], ui.sidebar.toggle) // #5663 - common QWERTY, AZERTY
|
||||
.on('←', pan([panPixels, 0]))
|
||||
.on('↑', pan([0, panPixels]))
|
||||
.on('→', pan([-panPixels, 0]))
|
||||
|
||||
@@ -179,11 +179,14 @@ export function uiShortcuts(context) {
|
||||
arr = ['Y'];
|
||||
} else if (detected.os !== 'mac' && d.text === 'shortcuts.browsing.display_options.fullscreen') {
|
||||
arr = ['F11'];
|
||||
} else if (d.text === 'shortcuts.browsing.display_options.sidebar') {
|
||||
arr = _uniq([t('sidebar.key'), '`', '²']); // #5663
|
||||
}
|
||||
|
||||
return arr.map(function(s) {
|
||||
// replace translations
|
||||
arr = arr.map(function(s) {
|
||||
return uiCmd.display(s.indexOf('.') !== -1 ? t(s) : s);
|
||||
});
|
||||
|
||||
return _uniq(arr).map(function(s) {
|
||||
return {
|
||||
shortcut: s,
|
||||
separator: d.separator
|
||||
@@ -195,17 +198,14 @@ export function uiShortcuts(context) {
|
||||
var selection = d3_select(this);
|
||||
var click = d.shortcut.toLowerCase().match(/(.*).click/);
|
||||
|
||||
if (click && click[1]) {
|
||||
if (click && click[1]) { // replace "left_click", "right_click" with mouse icon
|
||||
selection
|
||||
.call(svgIcon('#iD-walkthrough-mouse', 'mouseclick', click[1]));
|
||||
} else {
|
||||
selection
|
||||
.append('kbd')
|
||||
.attr('class', 'shortcut')
|
||||
.text(function (d) {
|
||||
var key = d.shortcut;
|
||||
return key.indexOf('.') !== -1 ? uiCmd.display(t(key)) : uiCmd.display(key);
|
||||
});
|
||||
.text(function (d) { return d.shortcut; });
|
||||
}
|
||||
|
||||
if (i < nodes.length - 1) {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import _isFunction from 'lodash-es/isFunction';
|
||||
import _uniq from 'lodash-es/uniq';
|
||||
|
||||
import {
|
||||
event as d3_event,
|
||||
@@ -125,7 +126,7 @@ export function utilKeybinding(namespace) {
|
||||
|
||||
// Remove one or more keycode bindings.
|
||||
keybinding.off = function(codes, capture) {
|
||||
var arr = [].concat(codes);
|
||||
var arr = _uniq([].concat(codes));
|
||||
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
var id = arr[i] + (capture ? '-capture' : '-bubble');
|
||||
@@ -141,7 +142,7 @@ export function utilKeybinding(namespace) {
|
||||
return keybinding.off(codes, capture);
|
||||
}
|
||||
|
||||
var arr = [].concat(codes);
|
||||
var arr = _uniq([].concat(codes));
|
||||
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
var id = arr[i] + (capture ? '-capture' : '-bubble');
|
||||
|
||||
Reference in New Issue
Block a user