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

80% Statements 8/10
75% Branches 6/8
100% Functions 1/1
80% Lines 8/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                                58x 2x     56x   56x       56x       56x 55x 55x      
import { state } from '../../store';
import getActiveToolForMouseEvent from '../shared/getActiveToolForMouseEvent';
import { setAnnotationSelected } from '../../stateManagement/annotation/annotationSelection';
import { 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.
  if (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);
  }
}