Virtual whiteboard for sketching hand-drawn like diagrams
fix: Incorrect point offsetting in LinearElementEditor.movePoints() (#8145)
Márk Tolmácsba8c09d52937
diff --git a/packages/excalidraw/element/linearElementEditor.ts b/packages/excalidraw/element/linearElementEditor.tsindex 48b33d150b..244bc275aa 100644--- a/packages/excalidraw/element/linearElementEditor.ts+++ b/packages/excalidraw/element/linearElementEditor.ts@@ -1165,7 +1165,7 @@ export class LinearElementEditor {const nextPoints = points.map((point, idx) => {const selectedPointData = targetPoints.find((p) => p.index === idx);if (selectedPointData) {- if (selectedOriginPoint) {+ if (selectedPointData.index === 0) {return point;}@@ -1174,7 +1174,10 @@ export class LinearElementEditor {const deltaY =selectedPointData.point[1] - points[selectedPointData.index][1];- return [point[0] + deltaX, point[1] + deltaY] as const;+ return [+ point[0] + deltaX - offsetX,+ point[1] + deltaY - offsetY,+ ] as const;}return offsetX || offsetY? ([point[0] - offsetX, point[1] - offsetY] as const)diff --git a/packages/excalidraw/tests/linearElementEditor.test.tsx b/packages/excalidraw/tests/linearElementEditor.test.tsxindex 692f0b1e45..00273f51de 100644--- a/packages/excalidraw/tests/linearElementEditor.test.tsx+++ b/packages/excalidraw/tests/linearElementEditor.test.tsx@@ -27,6 +27,7 @@ import * as textElementUtils from "../element/textElement";import { ROUNDNESS, VERTICAL_ALIGN } from "../constants";import { vi } from "vitest";import { arrayToMap } from "../utils";+import React from "react";const renderInteractiveScene = vi.spyOn(InteractiveCanvas,@@ -972,10 +973,10 @@ describe("Test Linear Elements", () => {]);expect((h.elements[1] as ExcalidrawTextElementWithContainer).text).toMatchInlineSnapshot(`- "Online whiteboard- collaboration made- easy"- `);+ "Online whiteboard+ collaboration made+ easy"+ `);});it("should bind text to arrow when clicked on arrow and enter pressed", async () => {@@ -1006,10 +1007,10 @@ describe("Test Linear Elements", () => {]);expect((h.elements[1] as ExcalidrawTextElementWithContainer).text).toMatchInlineSnapshot(`- "Online whiteboard- collaboration made- easy"- `);+ "Online whiteboard+ collaboration made+ easy"+ `);});it("should not bind text to line when double clicked", async () => {@@ -1349,4 +1350,27 @@ describe("Test Linear Elements", () => {expect(label.y).toBe(0);});});++ describe("Test moving linear element points", () => {+ it("should move the endpoint in the negative direction correctly when the start point is also moved in the positive direction", async () => {+ const line = createThreePointerLinearElement("arrow");+ const [origStartX, origStartY] = [line.x, line.y];++ LinearElementEditor.movePoints(line, [+ { index: 0, point: [line.points[0][0] + 10, line.points[0][1] + 10] },+ {+ index: line.points.length - 1,+ point: [+ line.points[line.points.length - 1][0] - 10,+ line.points[line.points.length - 1][1] - 10,+ ],+ },+ ]);+ expect(line.x).toBe(origStartX + 10);+ expect(line.y).toBe(origStartY + 10);++ expect(line.points[line.points.length - 1][0]).toBe(20);+ expect(line.points[line.points.length - 1][1]).toBe(-20);+ });+ });});