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

Code before:

      // Calculate next point in the line at a distance of sampling interval
      samplingInterval += threshold;

      const distanceRatio = samplingInterval / distance;
      const nextX =
        (1 - distanceRatio) * point.x + distanceRatio * scenePointer.x;
      const nextY =
        (1 - distanceRatio) * point.y + distanceRatio * scenePointer.y;
      point.x = nextX;
      point.y = nextY;
    }

    const hitElement = this.getElementAtPosition(
      scenePointer.x,
      scenePointer.y,
    );
    if (hitElement) {
      idsToUpdate.push(hitElement.id);
      if (event.altKey) {
        if (pointerDownState.elementIdsToErase[hitElement.id]) {
          pointerDownState.elementIdsToErase[hitElement.id] = false;
        }
      } else {
        pointerDownState.elementIdsToErase[hitElement.id] = true;
      }
    }

    const elements = this.scene.getElements().map((ele) => {
      const id =
        isBoundToContainer(ele) && idsToUpdate.includes(ele.containerId)
          ? ele.containerId
          : ele.id;
      if (idsToUpdate.includes(id)) {
        if (event.altKey) {
          if (pointerDownState.elementIdsToErase[id] === false) {
            return newElementWith(ele, {
              opacity: this.state.currentItemOpacity,
            });
          }
        } else {
          return newElementWith(ele, { opacity: 20 });
        }
      }
      return ele;
    });

    this.scene.replaceAllElements(elements);

    pointerDownState.lastCoords.x = scenePointer.x;
    pointerDownState.lastCoords.y = scenePointer.y;

Review comment (suggestion):
I'd not mutate the event because you never know where it'll be used after this function calls (potentially even later in this function). Let's just keep the positions as local variables

Code after:
      pointerDownState.lastCoords.y,
      scenePointer.x,
      scenePointer.y,
    );
    const threshold = 10 / this.state.zoom.value;
    const point = { ...pointerDownState.lastCoords };
    let samplingInterval = 0;
    while (samplingInterval <= distance) {
      const hitElements = this.getElementsAtPosition(point.x, point.y);
      updateElementIds(hitElements);

      // Exit since we reached current point
      if (samplingInterval === distance) {
        break;
      }

      // Calculate next point in the line at a distance of sampling interval
      samplingInterval = Math.min(samplingInterval + threshold, distance);

      const distanceRatio = samplingInterval / distance;
      const nextX =
        (1 - distanceRatio) * point.x + distanceRatio * scenePointer.x;
      const nextY =
        (1 - distanceRatio) * point.y + distanceRatio * scenePointer.y;
      point.x = nextX;
      point.y = nextY;
    }

    const elements = this.scene.getElements().map((ele) => {
      const id =
        isBoundToContainer(ele) && idsToUpdate.includes(ele.containerId)
          ? ele.containerId
          : ele.id;
      if (idsToUpdate.includes(id)) {
        if (event.altKey) {
          if (pointerDownState.elementIdsToErase[id] === false) {
            return newElementWith(ele, {
              opacity: this.state.currentItemOpacity,
            });
          }
        } else {
          return newElementWith(ele, { opacity: 20 });
        }
      }
      return ele;
    });

    this.scene.replaceAllElements(elements);

    pointerDownState.lastCoords.x = scenePointer.x;
    pointerDownState.lastCoords.y = scenePointer.y;