hyper/app/utils/keymaps/normalize.js
2017-09-20 01:39:55 +02:00

17 lines
571 B
JavaScript

// This function receives a keymap in any key order and returns
// the same keymap alphatetically sorted by the clients locale.
// eg.: cmd+alt+o -> alt+cmd+o
// We do this in order to normalize what the user defined to what we
// internally parse. By doing this, you can set your keymaps in any given order
// eg.: alt+cmd+o, cmd+alt+o, o+alt+cmd, etc. #2195
module.exports = keybinding => {
function sortAlphabetically(a, b) {
return a.localeCompare(b);
}
return keybinding
.toLowerCase()
.split('+')
.sort(sortAlphabetically)
.join('+');
};