All files / tools/src/eventDispatchers/mouseEventHandlers mouseDownActivate.ts

70% Statements 7/10
62.5% Branches 5/8
100% Functions 1/1
70% Lines 7/10

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                                74x       74x   74x       74x       74x 40x 40x      
import { state } from '../../store/state';
import getActiveToolForMouseEvent from '../shared/getActiveToolForMouseEvent';
import { setAnnotationSelected } from '../../stateManagement/annotation/annotationSelection';
import type { EventTypes } from '../../types';
 
/**
 * If the `mouseDown` handler does not consume an event,
 * activate the creation loop of the active tool, if one is found for the
 * mouse button pressed.
 *
 * @param evt - The normalized mouseDown event.
 */
export default function mouseDownActivate(
  evt: EventTypes.MouseDownActivateEventType
) {
  // If a tool has locked the current state it is dealing with an interaction within its own eventLoop.
  Iif (state.isInteractingWithTool) {
    return;
  }
 
  const activeTool = getActiveToolForMouseEvent(evt);
 
  Iif (!activeTool) {
    return;
  }
 
  Iif (state.isMultiPartToolActive) {
    return;
  }
 
  if (activeTool.addNewAnnotation) {
    const annotation = activeTool.addNewAnnotation(evt, 'mouse');
    setAnnotationSelected(annotation.annotationUID);
  }
}