feat: Call actionFinalize at the end of arrow creation and drag (#9453)
* First iter Signed-off-by: Mark Tolmacs <mark@lazycat.hu> * Restore binding Signed-off-by: Mark Tolmacs <mark@lazycat.hu> * More actionFinalize Signed-off-by: Mark Tolmacs <mark@lazycat.hu> * Additional fixes Signed-off-by: Mark Tolmacs <mark@lazycat.hu> * New elbow arrow is removed if too small Signed-off-by: Mark Tolmacs <mark@lazycat.hu> * Remove very small arrows * Still allow loops * Restore tests Signed-off-by: Mark Tolmacs <mark@lazycat.hu> * Update history snapshot * More history snapshot updates * keep invisible 2-point lines/freedraw elements --------- Signed-off-by: Mark Tolmacs <mark@lazycat.hu> Co-authored-by: dwelle <5153846+dwelle@users.noreply.github.com>
This commit is contained in:
@@ -6,7 +6,10 @@ import { DEFAULT_SIDEBAR, FONT_FAMILY, ROUNDNESS } from "@excalidraw/common";
|
||||
import { newElementWith } from "@excalidraw/element";
|
||||
import * as sizeHelpers from "@excalidraw/element";
|
||||
|
||||
import type { LocalPoint } from "@excalidraw/math";
|
||||
|
||||
import type {
|
||||
ExcalidrawArrowElement,
|
||||
ExcalidrawElement,
|
||||
ExcalidrawFreeDrawElement,
|
||||
ExcalidrawLinearElement,
|
||||
@@ -163,6 +166,109 @@ describe("restoreElements", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("should remove imperceptibly small elements", () => {
|
||||
const arrowElement = API.createElement({
|
||||
type: "arrow",
|
||||
points: [
|
||||
[0, 0],
|
||||
[0.02, 0.05],
|
||||
] as LocalPoint[],
|
||||
x: 0,
|
||||
y: 0,
|
||||
});
|
||||
|
||||
const restoredElements = restore.restoreElements([arrowElement], null);
|
||||
|
||||
const restoredArrow = restoredElements[0] as
|
||||
| ExcalidrawArrowElement
|
||||
| undefined;
|
||||
|
||||
expect(restoredArrow).toBeUndefined();
|
||||
});
|
||||
|
||||
it("should keep 'imperceptibly' small freedraw/line elements", () => {
|
||||
const freedrawElement = API.createElement({
|
||||
type: "freedraw",
|
||||
points: [
|
||||
[0, 0],
|
||||
[0.0001, 0.0001],
|
||||
] as LocalPoint[],
|
||||
x: 0,
|
||||
y: 0,
|
||||
});
|
||||
const lineElement = API.createElement({
|
||||
type: "line",
|
||||
points: [
|
||||
[0, 0],
|
||||
[0.0001, 0.0001],
|
||||
] as LocalPoint[],
|
||||
x: 0,
|
||||
y: 0,
|
||||
});
|
||||
|
||||
const restoredElements = restore.restoreElements(
|
||||
[freedrawElement, lineElement],
|
||||
null,
|
||||
);
|
||||
|
||||
expect(restoredElements).toEqual([
|
||||
expect.objectContaining({ id: freedrawElement.id }),
|
||||
expect.objectContaining({ id: lineElement.id }),
|
||||
]);
|
||||
});
|
||||
|
||||
it("should restore loop linears correctly", () => {
|
||||
const linearElement = API.createElement({
|
||||
type: "line",
|
||||
points: [
|
||||
[0, 0],
|
||||
[100, 100],
|
||||
[100, 200],
|
||||
[0, 0],
|
||||
] as LocalPoint[],
|
||||
x: 0,
|
||||
y: 0,
|
||||
});
|
||||
const arrowElement = API.createElement({
|
||||
type: "arrow",
|
||||
points: [
|
||||
[0, 0],
|
||||
[100, 100],
|
||||
[100, 200],
|
||||
[0, 0],
|
||||
] as LocalPoint[],
|
||||
x: 500,
|
||||
y: 500,
|
||||
});
|
||||
|
||||
const restoredElements = restore.restoreElements(
|
||||
[linearElement, arrowElement],
|
||||
null,
|
||||
);
|
||||
|
||||
const restoredLinear = restoredElements[0] as
|
||||
| ExcalidrawLinearElement
|
||||
| undefined;
|
||||
const restoredArrow = restoredElements[1] as
|
||||
| ExcalidrawArrowElement
|
||||
| undefined;
|
||||
|
||||
expect(restoredLinear?.type).toBe("line");
|
||||
expect(restoredLinear?.points).toEqual([
|
||||
[0, 0],
|
||||
[100, 100],
|
||||
[100, 200],
|
||||
[0, 0],
|
||||
] as LocalPoint[]);
|
||||
expect(restoredArrow?.type).toBe("arrow");
|
||||
expect(restoredArrow?.points).toEqual([
|
||||
[0, 0],
|
||||
[100, 100],
|
||||
[100, 200],
|
||||
[0, 0],
|
||||
] as LocalPoint[]);
|
||||
});
|
||||
|
||||
it('should set arrow element endArrowHead as "arrow" when arrow element endArrowHead is null', () => {
|
||||
const arrowElement = API.createElement({ type: "arrow" });
|
||||
const restoredElements = restore.restoreElements([arrowElement], null);
|
||||
|
||||
Reference in New Issue
Block a user