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:
Bryan Housel
2019-01-07 11:12:24 -05:00
parent 55d2dddb70
commit 826f66a91b
4 changed files with 25 additions and 27 deletions

View File

@@ -62,12 +62,12 @@
"text": "shortcuts.browsing.display_options.map_data"
},
{
"modifiers": ["⌃","⌘"],
"modifiers": ["⌃", "⌘"],
"shortcuts": ["F", "F11"],
"text": "shortcuts.browsing.display_options.fullscreen"
},
{
"shortcuts": ["sidebar.key"],
"shortcuts": ["sidebar.key", "`", "²"],
"text": "shortcuts.browsing.display_options.sidebar"
},
{
@@ -127,19 +127,19 @@
"text": "shortcuts.browsing.vertex_selected.previous"
},
{
"shortcuts": ["]","↘"],
"shortcuts": ["]", "↘"],
"text": "shortcuts.browsing.vertex_selected.next"
},
{
"shortcuts": ["{","⇞"],
"shortcuts": ["{", "⇞"],
"text": "shortcuts.browsing.vertex_selected.first"
},
{
"shortcuts": ["}","⇟"],
"shortcuts": ["}", "⇟"],
"text": "shortcuts.browsing.vertex_selected.last"
},
{
"shortcuts": ["\\","shortcuts.key.pause"],
"shortcuts": ["\\", "shortcuts.key.pause"],
"text": "shortcuts.browsing.vertex_selected.change_parent"
}
]
@@ -173,7 +173,7 @@
"text": "shortcuts.editing.drawing.add_note"
},
{
"shortcuts": ["Left-click","shortcuts.key.space"],
"shortcuts": ["Left-click", "shortcuts.key.space"],
"text": "shortcuts.editing.drawing.place_point"
},
{
@@ -181,7 +181,7 @@
"text": "shortcuts.editing.drawing.disable_snap"
},
{
"shortcuts": ["↵","⎋"],
"shortcuts": ["↵", "⎋"],
"text": "shortcuts.editing.drawing.stop_line"
},
{
@@ -204,7 +204,7 @@
"text": "shortcuts.editing.commands.undo"
},
{
"modifiers": ["⌘","⇧"],
"modifiers": ["⌘", "⇧"],
"shortcuts": ["Z"],
"text": "shortcuts.editing.commands.redo"
},
@@ -294,22 +294,22 @@
"text": "shortcuts.tools.info.all"
},
{
"modifiers": ["⌘","⇧"],
"modifiers": ["⌘", "⇧"],
"shortcuts": ["info_panels.background.key"],
"text": "shortcuts.tools.info.background"
},
{
"modifiers": ["⌘","⇧"],
"modifiers": ["⌘", "⇧"],
"shortcuts": ["info_panels.history.key"],
"text": "shortcuts.tools.info.history"
},
{
"modifiers": ["⌘","⇧"],
"modifiers": ["⌘", "⇧"],
"shortcuts": ["info_panels.location.key"],
"text": "shortcuts.tools.info.location"
},
{
"modifiers": ["⌘","⇧"],
"modifiers": ["⌘", "⇧"],
"shortcuts": ["info_panels.measurement.key"],
"text": "shortcuts.tools.info.measurement"
}

View File

@@ -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]))

View File

@@ -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) {

View File

@@ -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');