Repository: excalidraw/excalidraw
File: src/element/linearElementEditor.ts (TypeScript)

Code before:
      return false;
    }

    const { selectedPointsIndices, elementId, pointerDownState } =
      linearElementEditor;
    const { prevSelectedPointsIndices } = pointerDownState;
    const element = LinearElementEditor.getElement(elementId);
    if (!element) {
      return false;
    }

    // point that's being dragged (out of all selected points)
    const draggingPoint = element.points[
      linearElementEditor.pointerDownState.lastClickedPoint
    ] as [number, number] | undefined;
    if (selectedPointsIndices && draggingPoint) {
      if (
        shouldRotateWithDiscreteAngle(event) &&
        (selectedPointsIndices.length === 1 ||
          prevSelectedPointsIndices?.length === 1) &&
        element.points.length > 1
      ) {
        const prevSelectedIndex = prevSelectedPointsIndices?.[0];
        const selectedIndex = selectedPointsIndices.filter(
          (i) => i !== prevSelectedIndex,
        )?.[0];
        const referencePoint =
          element.points[selectedIndex === 0 ? 1 : selectedIndex - 1];

        let [width, height] = LinearElementEditor._getShiftLockedDelta(
          element,
          referencePoint,
          [scenePointerX, scenePointerY],
          appState.gridSize,
        );

        // rounding to stop the dragged point from jiggling
        width = Math.round(width);
        height = Math.round(height);

        LinearElementEditor.movePoints(element, [
          {
            index: selectedIndex,
            point: [width + referencePoint[0], height + referencePoint[1]],
            isDragging:
              selectedIndex ===
              linearElementEditor.pointerDownState.lastClickedPoint,
          },
        ]);
      } else {
        const newDraggingPointPosition = LinearElementEditor.createPointAt(

Review comment (bug):
not sure what the goal here is exactly with filtering out previous selected points? EIther way, this will fail when you click on the same point twice. And since array access isn't type-safe (until we switch the TS compiler flag to make it safe), this will break.

Code after:
    ) => void,
    linearElementEditor: LinearElementEditor,
  ): boolean {
    if (!linearElementEditor) {
      return false;
    }

    const { selectedPointsIndices, elementId } = linearElementEditor;
    const element = LinearElementEditor.getElement(elementId);
    if (!element) {
      return false;
    }

    // point that's being dragged (out of all selected points)
    const draggingPoint = element.points[
      linearElementEditor.pointerDownState.lastClickedPoint
    ] as [number, number] | undefined;
    if (selectedPointsIndices && draggingPoint) {
      if (
        shouldRotateWithDiscreteAngle(event) &&
        selectedPointsIndices.length === 1 &&
        element.points.length > 1
      ) {
        const selectedIndex = selectedPointsIndices[0];
        const referencePoint =
          element.points[selectedIndex === 0 ? 1 : selectedIndex - 1];

        let [width, height] = LinearElementEditor._getShiftLockedDelta(
          element,
          referencePoint,
          [scenePointerX, scenePointerY],
          appState.gridSize,
        );

        // rounding to stop the dragged point from jiggling
        width = Math.round(width);
        height = Math.round(height);

        LinearElementEditor.movePoints(element, [
          {
            index: selectedIndex,
            point: [width + referencePoint[0], height + referencePoint[1]],
            isDragging:
              selectedIndex ===
              linearElementEditor.pointerDownState.lastClickedPoint,
          },
        ]);
      } else {
        const newDraggingPointPosition = LinearElementEditor.createPointAt(
          element,
          scenePointerX - linearElementEditor.pointerOffset.x,