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

Function _getMatches

client/vendors/mousetrap.js:317–375  ·  view source on GitHub ↗

* finds all callbacks that match based on the keycode, modifiers, * and action * * @param {string} character * @param {Array} modifiers * @param {Event|Object} e * @param {string=} sequenceName - name of the sequence we are looking for * @param {string=} combinatio

(character, modifiers, e, sequenceName, combination, level)

Source from the content-addressed store, hash-verified

315 * @returns {Array}
316 */
317 function _getMatches(character, modifiers, e, sequenceName, combination, level) {
318 var i,
319 callback,
320 matches = [],
321 action = e.type;
322
323 // if there are no events related to this keycode
324 if (!_callbacks[character]) {
325 return [];
326 }
327
328 // if a modifier key is coming up on its own we should allow it
329 if (action == 'keyup' && _isModifier(character)) {
330 modifiers = [character];
331 }
332
333 // loop through all callbacks for the key that was pressed
334 // and see if any of them match
335 for (i = 0; i < _callbacks[character].length; ++i) {
336 callback = _callbacks[character][i];
337
338 // if a sequence name is not specified, but this is a sequence at
339 // the wrong level then move onto the next match
340 if (!sequenceName && callback.seq && _sequenceLevels[callback.seq] != callback.level) {
341 continue;
342 }
343
344 // if the action we are looking for doesn't match the action we got
345 // then we should keep going
346 if (action != callback.action) {
347 continue;
348 }
349
350 // if this is a keypress event and the meta key and control key
351 // are not pressed that means that we need to only look at the
352 // character, otherwise check the modifiers as well
353 //
354 // chrome will not fire a keypress if meta or control is down
355 // safari will fire a keypress if meta or meta+shift is down
356 // firefox will fire a keypress if meta or control is down
357 if ((action == 'keypress' && !e.metaKey && !e.ctrlKey) || _modifiersMatch(modifiers, callback.modifiers)) {
358
359 // when you bind a combination or sequence a second time it
360 // should overwrite the first one. if a sequenceName or
361 // combination is specified in this call it does just that
362 //
363 // @todo make deleting its own method?
364 var deleteCombo = !sequenceName && callback.combo == combination;
365 var deleteSequence = sequenceName && callback.seq == sequenceName && callback.level == level;
366 if (deleteCombo || deleteSequence) {
367 _callbacks[character].splice(i, 1);
368 }
369
370 matches.push(callback);
371 }
372 }
373
374 return matches;

Callers 2

_handleKeyFunction · 0.85
_bindSingleFunction · 0.85

Calls 2

_isModifierFunction · 0.85
_modifiersMatchFunction · 0.85

Tested by

no test coverage detected