Repository: excalidraw/excalidraw
File: src/components/App.tsx (TypeScript)

Code before:
  ): ExcalidrawElement | undefined => {
    // Reversing so we traverse the elements in decreasing order
    // of z-index
    const elements = this.scene.getElements().slice().reverse();
    let hitElementIndex = Infinity;

    return elements.find((element, index) => {
      if (hitElement && element.id === hitElement.id) {
        hitElementIndex = index;
      }
      return (
        element.link &&
        isPointHittingLinkIcon(
          element,
          this.state,
          [scenePointer.x, scenePointer.y],
          this.isMobile,
        ) &&
        index <= hitElementIndex
      );
    });
  };

  private redirectToLink = () => {
    if (
      (!this.isMobile &&
       ( this.lastPointerDown!.clientX !== this.lastPointerUp!.clientX ||
          this.lastPointerDown!.clientY !== this.lastPointerUp!.clientY)) ||
      distance2d(
        this.lastPointerDown!.clientX,
        this.lastPointerDown!.clientY,
        this.lastPointerUp!.clientX,
        this.lastPointerUp!.clientY,
      ) > DRAGGING_THRESHOLD
    ) {
      return;
    }
    const lastPointerDownCoords = viewportCoordsToSceneCoords(
      this.lastPointerDown!,
      this.state,
    );
    const lastPointerDownHittingLinkIcon = isPointHittingLinkIcon(
      this.hitLinkElement!,
      this.state,
      [lastPointerDownCoords.x, lastPointerDownCoords.y],
      this.isMobile,
    );
    const lastPointerUpCoords = viewportCoordsToSceneCoords(
      this.lastPointerUp!,
      this.state,
    );

Review comment (suggestion):
can you reverse the conditions, first ` this.isMobile && distance() || (strict check), for better readability
Or it could be further simpliefied to just checking the distance =>
store distance in  a variable and check if its greater than threshold when mobile or 0 otherwise for strict check

Code after:
    scenePointer: Readonly<{ x: number; y: number }>,
    hitElement: NonDeletedExcalidrawElement | null,
  ): ExcalidrawElement | undefined => {
    // Reversing so we traverse the elements in decreasing order
    // of z-index
    const elements = this.scene.getElements().slice().reverse();
    let hitElementIndex = Infinity;

    return elements.find((element, index) => {
      if (hitElement && element.id === hitElement.id) {
        hitElementIndex = index;
      }
      return (
        element.link &&
        isPointHittingLinkIcon(
          element,
          this.state,
          [scenePointer.x, scenePointer.y],
          this.isMobile,
        ) &&
        index <= hitElementIndex
      );
    });
  };

  private redirectToLink = (
    event: React.PointerEvent<HTMLCanvasElement>,
    isTouchScreen: boolean,
  ) => {
    const draggedDistance = distance2d(
      this.lastPointerDown!.clientX,
      this.lastPointerDown!.clientY,
      this.lastPointerUp!.clientX,
      this.lastPointerUp!.clientY,
    );
    if (
      !this.hitLinkElement ||
      // For touch screen allow dragging threshold else strict check
      (isTouchScreen && draggedDistance > DRAGGING_THRESHOLD) ||
      (!isTouchScreen && draggedDistance !== 0)
    ) {
      return;
    }
    const lastPointerDownCoords = viewportCoordsToSceneCoords(
      this.lastPointerDown!,
      this.state,
    );
    const lastPointerDownHittingLinkIcon = isPointHittingLinkIcon(
      this.hitLinkElement!,
      this.state,
      [lastPointerDownCoords.x, lastPointerDownCoords.y],