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

90% Statements 9/10
87.5% Branches 7/8
100% Functions 1/1
90% Lines 9/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                                90x 14x     76x   76x 1x     75x       75x 72x 72x      
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);
 
  if (!activeTool) {
    return;
  }
 
  Iif (state.isMultiPartToolActive) {
    return;
  }
 
  if (activeTool.addNewAnnotation) {
    const annotation = activeTool.addNewAnnotation(evt, 'mouse');
    setAnnotationSelected(annotation.annotationUID);
  }
}