Files
iD/modules/ui/cmd.js
Bryan Housel cb71e90384 Module for iD.Detect() (#3243)
* convert iD.Detect() iife to a module

* iD.Detect() should return loaded locale (except for 'en')

(The previous code was a hack to replace the detected locale with the loaded
locale.  Now that Detect is a module, we can not replace the detected locale
from external code, but we can have Detect() return the locale we really want)
2016-07-13 09:15:47 -04:00

35 lines
780 B
JavaScript

import { Detect } from '../util/detect';
// Translate a MacOS key command into the appropriate Windows/Linux equivalent.
// For example, ⌘Z -> Ctrl+Z
export function cmd(code) {
var detected = Detect();
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]] + '+';
} else {
result += code[i];
}
}
return result;
}