Files
iD/modules/ui/cmd.js
Bryan Housel e83b2ea2be Allow delete key without modifier as shortcut for deleting
(closes #3455)

Also fixed a minor bug in `iD.uiCmd` that was causing keyboard shortcuts
like '⌘⌫' to convert to 'Ctrl+Backspace+'  (note extra trailing '+')
It affected only the tooltip display, not the key event binding.
2016-10-24 23:57:44 -04:00

36 lines
820 B
JavaScript

import { utilDetect } from '../util/detect';
// Translate a MacOS key command into the appropriate Windows/Linux equivalent.
// For example, ⌘Z -> Ctrl+Z
export function uiCmd(code) {
var detected = utilDetect();
if (detected.os === 'mac') {
return code;
}
if (detected.os === 'win') {
if (code === '⌘⇧Z') return 'Ctrl+Y';
}
var result = '',
replacements = {
'⌘': 'Ctrl',
'⇧': 'Shift',
'⌥': 'Alt',
'⌫': 'Backspace',
'⌦': 'Delete'
};
for (var i = 0; i < code.length; i++) {
if (code[i] in replacements) {
result += replacements[code[i]] + (i < code.length - 1 ? '+' : '');
} else {
result += code[i];
}
}
return result;
}