mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
fix: filter out elements not overlapping frame on paste (#7591)
This commit is contained in:
parent
4997624a3a
commit
740a165452
3 changed files with 198 additions and 7 deletions
|
@ -292,4 +292,141 @@ describe("pasting & frames", () => {
|
|||
expect(h.elements[1].frameId).toBe(frame.id);
|
||||
});
|
||||
});
|
||||
|
||||
it("should filter out elements not overlapping frame", async () => {
|
||||
const frame = API.createElement({
|
||||
type: "frame",
|
||||
width: 100,
|
||||
height: 100,
|
||||
x: 0,
|
||||
y: 0,
|
||||
});
|
||||
const rect = API.createElement({
|
||||
type: "rectangle",
|
||||
width: 50,
|
||||
height: 50,
|
||||
});
|
||||
const rect2 = API.createElement({
|
||||
type: "rectangle",
|
||||
width: 50,
|
||||
height: 50,
|
||||
x: 100,
|
||||
y: 100,
|
||||
});
|
||||
|
||||
h.elements = [frame];
|
||||
|
||||
const clipboardJSON = await serializeAsClipboardJSON({
|
||||
elements: [rect, rect2],
|
||||
files: null,
|
||||
});
|
||||
|
||||
mouse.moveTo(90, 90);
|
||||
|
||||
pasteWithCtrlCmdV(clipboardJSON);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(h.elements.length).toBe(3);
|
||||
expect(h.elements[1].type).toBe(rect.type);
|
||||
expect(h.elements[1].frameId).toBe(frame.id);
|
||||
expect(h.elements[2].type).toBe(rect2.type);
|
||||
expect(h.elements[2].frameId).toBe(null);
|
||||
});
|
||||
});
|
||||
|
||||
it("should not filter out elements not overlapping frame if part of group", async () => {
|
||||
const frame = API.createElement({
|
||||
type: "frame",
|
||||
width: 100,
|
||||
height: 100,
|
||||
x: 0,
|
||||
y: 0,
|
||||
});
|
||||
const rect = API.createElement({
|
||||
type: "rectangle",
|
||||
width: 50,
|
||||
height: 50,
|
||||
groupIds: ["g1"],
|
||||
});
|
||||
const rect2 = API.createElement({
|
||||
type: "rectangle",
|
||||
width: 50,
|
||||
height: 50,
|
||||
x: 100,
|
||||
y: 100,
|
||||
groupIds: ["g1"],
|
||||
});
|
||||
|
||||
h.elements = [frame];
|
||||
|
||||
const clipboardJSON = await serializeAsClipboardJSON({
|
||||
elements: [rect, rect2],
|
||||
files: null,
|
||||
});
|
||||
|
||||
mouse.moveTo(90, 90);
|
||||
|
||||
pasteWithCtrlCmdV(clipboardJSON);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(h.elements.length).toBe(3);
|
||||
expect(h.elements[1].type).toBe(rect.type);
|
||||
expect(h.elements[1].frameId).toBe(frame.id);
|
||||
expect(h.elements[2].type).toBe(rect2.type);
|
||||
expect(h.elements[2].frameId).toBe(frame.id);
|
||||
});
|
||||
});
|
||||
|
||||
it("should not filter out other frames and their children", async () => {
|
||||
const frame = API.createElement({
|
||||
type: "frame",
|
||||
width: 100,
|
||||
height: 100,
|
||||
x: 0,
|
||||
y: 0,
|
||||
});
|
||||
const rect = API.createElement({
|
||||
type: "rectangle",
|
||||
width: 50,
|
||||
height: 50,
|
||||
groupIds: ["g1"],
|
||||
});
|
||||
|
||||
const frame2 = API.createElement({
|
||||
type: "frame",
|
||||
width: 75,
|
||||
height: 75,
|
||||
x: 0,
|
||||
y: 0,
|
||||
});
|
||||
const rect2 = API.createElement({
|
||||
type: "rectangle",
|
||||
width: 50,
|
||||
height: 50,
|
||||
x: 55,
|
||||
y: 55,
|
||||
frameId: frame2.id,
|
||||
});
|
||||
|
||||
h.elements = [frame];
|
||||
|
||||
const clipboardJSON = await serializeAsClipboardJSON({
|
||||
elements: [rect, rect2, frame2],
|
||||
files: null,
|
||||
});
|
||||
|
||||
mouse.moveTo(90, 90);
|
||||
|
||||
pasteWithCtrlCmdV(clipboardJSON);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(h.elements.length).toBe(4);
|
||||
expect(h.elements[1].type).toBe(rect.type);
|
||||
expect(h.elements[1].frameId).toBe(frame.id);
|
||||
expect(h.elements[2].type).toBe(rect2.type);
|
||||
expect(h.elements[2].frameId).toBe(h.elements[3].id);
|
||||
expect(h.elements[3].type).toBe(frame2.type);
|
||||
expect(h.elements[3].frameId).toBe(null);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue