All files / packages/tools/src/eventDispatchers/shared getMouseModifier.ts

30% Statements 6/20
19.04% Branches 4/21
100% Functions 1/1
30% Lines 6/20

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41              1x   301x                       301x                 301x     301x     301x        
import { KeyboardBindings as kb } from '../../enums';
 
/**
 * Gets the mouse modifier key from a mouse event.
 * Supports Shift, Ctrl, Alt, in singly and in combinations of 2
 * Supports Meta singly.
 */
const getMouseModifierKey = (evt) => {
  // The logic is a hard coded key mapping
  Iif (evt.shiftKey) {
    if (evt.ctrlKey) {
      return kb.ShiftCtrl;
    }
    if (evt.altKey) {
      return kb.ShiftAlt;
    }
    if (evt.metaKey) {
      return kb.ShiftMeta;
    }
    return kb.Shift;
  }
  Iif (evt.ctrlKey) {
    if (evt.altKey) {
      return kb.CtrlAlt;
    }
    if (evt.metaKey) {
      return kb.CtrlMeta;
    }
    return kb.Ctrl;
  }
  Iif (evt.altKey) {
    return (evt.metaKey && kb.AltMeta) || kb.Alt;
  }
  Iif (evt.metaKey) {
    return kb.Meta;
  }
  return undefined;
};
 
export default getMouseModifierKey;