MCPcopy Index your code
hub / github.com/CodeboxIDE/codebox / _bindSingle

Function _bindSingle

client/vendors/mousetrap.js:790–831  ·  view source on GitHub ↗

* binds a single keyboard combination * * @param {string} combination * @param {Function} callback * @param {string=} action * @param {string=} sequenceName - name of sequence if part of sequence * @param {number=} level - what part of the sequence the command is *

(combination, callback, action, sequenceName, level)

Source from the content-addressed store, hash-verified

788 * @returns void
789 */
790 function _bindSingle(combination, callback, action, sequenceName, level) {
791
792 // store a direct mapped reference for use with Mousetrap.trigger
793 _directMap[combination + ':' + action] = callback;
794
795 // make sure multiple spaces in a row become a single space
796 combination = combination.replace(/\s+/g, ' ');
797
798 var sequence = combination.split(' '),
799 info;
800
801 // if this pattern is a sequence of keys then run through this method
802 // to reprocess each pattern one key at a time
803 if (sequence.length > 1) {
804 _bindSequence(combination, sequence, callback, action);
805 return;
806 }
807
808 info = _getKeyInfo(combination, action);
809
810 // make sure to initialize array if this is the first time
811 // a callback is added for this key
812 _callbacks[info.key] = _callbacks[info.key] || [];
813
814 // remove an existing match if there is one
815 _getMatches(info.key, info.modifiers, {type: info.action}, sequenceName, combination, level);
816
817 // add this call back to the array
818 // if it is a sequence put it at the beginning
819 // if not put it at the end
820 //
821 // this is important because the way these are processed expects
822 // the sequence ones to come first
823 _callbacks[info.key][sequenceName ? 'unshift' : 'push']({
824 callback: callback,
825 modifiers: info.modifiers,
826 action: info.action,
827 seq: sequenceName,
828 level: level,
829 combo: combination
830 });
831 }
832
833 /**
834 * binds multiple combinations to the same callback

Callers 2

_bindSequenceFunction · 0.85
_bindMultipleFunction · 0.85

Calls 3

_bindSequenceFunction · 0.85
_getKeyInfoFunction · 0.85
_getMatchesFunction · 0.85

Tested by

no test coverage detected