src/command/KeyBindingManager.js
function normalizeKeyDescriptorString(origDescriptor) {
        var hasMacCtrl = false,
            hasCtrl = false,
            hasAlt = false,
            hasShift = false,
            key = "",
            error = false;

        function _compareModifierString(left, right) {
            if (!left || !right) {
                return false;
            }
            left = left.trim().toLowerCase();
            right = right.trim().toLowerCase();

            return (left.length > 0 && left === right);
        }

        origDescriptor.split("-").forEach(function parseDescriptor(ele, i, arr) {
            if (_compareModifierString("ctrl", ele)) {
                if (brackets.platform === "mac") {
                    hasMacCtrl = true;
                } else {
                    hasCtrl = true;
                }
            } else if (_compareModifierString("cmd", ele)) {
                if (brackets.platform === "mac") {
                    hasCtrl = true;
                } else {
                    error = true;
                }
            } else if (_compareModifierString("alt", ele)) {
                hasAlt = true;
            } else if (_compareModifierString("opt", ele)) {
                if (brackets.platform === "mac") {
                    hasAlt = true;
                } else {
                    error = true;
                }
            } else if (_compareModifierString("shift", ele)) {
                hasShift = true;
            } else if (key.length > 0) {
                console.log("KeyBindingManager normalizeKeyDescriptorString() - Multiple keys defined. Using key: " + key + " from: " + origDescriptor);
                error = true;
            } else {
                key = ele;
            }
        });

        if (error) {
            return null;
        }

        // Check to see if the binding is for "-".
        if (key === "" && origDescriptor.search(/^.+--$/) !== -1) {
            key = "-";
        }

        // '+' char is valid if it's the only key. Keyboard shortcut strings should use
        // unicode characters (unescaped). Keyboard shortcut display strings may use
        // unicode escape sequences (e.g. \u20AC euro sign)
        if ((key.indexOf("+")) >= 0 && (key.length > 1)) {
            return null;
        }

        // Ensure that the first letter of the key name is in upper case and the rest are
        // in lower case. i.e. 'a' => 'A' and 'up' => 'Up'
        if (/^[a-z]/i.test(key)) {
            key = _.capitalize(key.toLowerCase());
        }

        // Also make sure that the second word of PageUp/PageDown has the first letter in upper case.
        if (/^Page/.test(key)) {
            key = key.replace(/(up|down)$/, function (match, p1) {
                return _.capitalize(p1);
            });
        }

        // No restriction on single character key yet, but other key names are restricted to either
        // Function keys or those listed in _keyNames array.
        if (key.length > 1 && !/F\d+/.test(key) &&
                _keyNames.indexOf(key) === -1) {
            return null;
        }

        return _buildKeyDescriptor(hasMacCtrl, hasCtrl, hasAlt, hasShift, key);
    }
function normalizeKeyDescriptorString(origDescriptor) {
        var hasMacCtrl = false,
            hasCtrl = false,
            hasAlt = false,
            hasShift = false,
            key = "",
            error = false;

        function _compareModifierString(left, right) {
            if (!left || !right) {
                return false;
            }
            left = left.trim().toLowerCase();
            right = right.trim().toLowerCase();

            return (left.length > 0 && left === right);
        }

        origDescriptor.split("-").forEach(function parseDescriptor(ele, i, arr) {
            if (_compareModifierString("ctrl", ele)) {
                if (brackets.platform === "mac") {
                    hasMacCtrl = true;
                } else {
                    hasCtrl = true;
                }
            } else if (_compareModifierString("cmd", ele)) {
                if (brackets.platform === "mac") {
                    hasCtrl = true;
                } else {
                    error = true;
                }
            } else if (_compareModifierString("alt", ele)) {
                hasAlt = true;
            } else if (_compareModifierString("opt", ele)) {
                if (brackets.platform === "mac") {
                    hasAlt = true;
                } else {
                    error = true;
                }
            } else if (_compareModifierString("shift", ele)) {
                hasShift = true;
            } else if (key.length > 0) {
                console.log("KeyBindingManager normalizeKeyDescriptorString() - Multiple keys defined. Using key: " + key + " from: " + origDescriptor);
                error = true;
            } else {
                key = ele;
            }
        });

        if (error) {
            return null;
        }

        // Check to see if the binding is for "-".
        if (key === "" && origDescriptor.search(/^.+--$/) !== -1) {
            key = "-";
        }

        // '+' char is valid if it's the only key. Keyboard shortcut strings should use
        // unicode characters (unescaped). Keyboard shortcut display strings may use
        // unicode escape sequences (e.g. \u20AC euro sign)
        if ((key.indexOf("+")) >= 0 && (key.length > 1)) {
            return null;
        }

        // Ensure that the first letter of the key name is in upper case and the rest are
        // in lower case. i.e. 'a' => 'A' and 'up' => 'Up'
        if (/^[a-z]/i.test(key)) {
            key = _.capitalize(key.toLowerCase());
        }

        // Also make sure that the second word of PageUp/PageDown has the first letter in upper case.
        if (/^Page/.test(key)) {
            key = key.replace(/(up|down)$/, function (match, p1) {
                return _.capitalize(p1);
            });
        }

        // No restriction on single character key yet, but other key names are restricted to either
        // Function keys or those listed in _keyNames array.
        if (key.length > 1 && !/F\d+/.test(key) &&
                _keyNames.indexOf(key) === -1) {
            return null;
        }

        return _buildKeyDescriptor(hasMacCtrl, hasCtrl, hasAlt, hasShift, key);
    }
function normalizeKeyDescriptorString ( origDescriptor ) { var hasMacCtrl = false , hasCtrl = false , hasAlt = false , hasShift = false , key = "" , error = false ; function _compareModifierString ( left , right ) { if ( ! left || ! right ) { return false ; } left = left . trim ( ) . toLowerCase ( ) ; right = right . trim ( ) . toLowerCase ( ) ; return ( left . length > 0 && left === right ) ; } origDescriptor . split ( "-" ) . forEach ( function parseDescriptor ( ele , i , arr ) { if ( _compareModifierString ( "ctrl" , ele ) ) { if ( brackets . platform === "mac" ) { hasMacCtrl = true ; } else { hasCtrl = true ; } } else if ( _compareModifierString ( "cmd" , ele ) ) { if ( brackets . platform === "mac" ) { hasCtrl = true ; } else { error = true ; } } else if ( _compareModifierString ( "alt" , ele ) ) { hasAlt = true ; } else if ( _compareModifierString ( "opt" , ele ) ) { if ( brackets . platform === "mac" ) { hasAlt = true ; } else { error = true ; } } else if ( _compareModifierString ( "shift" , ele ) ) { hasShift = true ; } else if ( key . length > 0 ) { console . log ( "KeyBindingManager normalizeKeyDescriptorString() - Multiple keys defined. Using key: " + key + " from: " + origDescriptor ) ; error = true ; } else { key = ele ; } } ) ; if ( error ) { return null ; } // Check to see if the binding is for "-". if ( key === "" && origDescriptor . search ( / ^.+--$ / ) !== - 1 ) { key = "-" ; } // '+' char is valid if it's the only key. Keyboard shortcut strings should use // unicode characters (unescaped). Keyboard shortcut display strings may use // unicode escape sequences (e.g. \u20AC euro sign) if ( ( key . indexOf ( "+" ) ) >= 0 && ( key . length > 1 ) ) { return null ; } // Ensure that the first letter of the key name is in upper case and the rest are // in lower case. i.e. 'a' => 'A' and 'up' => 'Up' if ( / ^[a-z] / i . test ( key ) ) { key = _ . capitalize ( key . toLowerCase ( ) ) ; } // Also make sure that the second word of PageUp/PageDown has the first letter in upper case. if ( / ^Page / . test ( key ) ) { key = key . replace ( / (up|down)$ / , function ( match , p1 ) { return _ . capitalize ( p1 ) ; } ) ; } // No restriction on single character key yet, but other key names are restricted to either // Function keys or those listed in _keyNames array. if ( key . length > 1 && ! / F\d+ / . test ( key ) && _keyNames . indexOf ( key ) === - 1 ) { return null ; } return _buildKeyDescriptor ( hasMacCtrl , hasCtrl , hasAlt , hasShift , key ) ; }
normalizes the incoming key descriptor so the modifier keys are always specified in the correct order
@param {string} The string for a key descriptor, can be in any order, the result will be Ctrl-Alt-Shift-<Key>
@return {string} The normalized key descriptor or null if the descriptor invalid
normalizes the incoming key descriptor so the modifier keys are always specified in the correct order