Skip to content

Commit

Permalink
[FIX] clipboard: wrong clipboard invalidation
Browse files Browse the repository at this point in the history
The CUT clipboard should be invalidated when inserting rows inside
of the CUT zone.

But we didn't check the sheet where the rows are
inserted, so the clipboard was invalidating when inserting rows inside
another sheet.

closes #4158

Task: 3901961
Signed-off-by: Lucas Lefèvre (lul) <lul@odoo.com>
  • Loading branch information
hokolomopo committed May 10, 2024
1 parent 4d672af commit f4034dd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/plugins/ui/clipboard.ts
Expand Up @@ -127,7 +127,7 @@ export class ClipboardPlugin extends UIPlugin {
this.status = "invisible";

// If we add a col/row inside or before the cut area, we invalidate the clipboard
if (this.state?.operation !== "CUT") {
if (this.state?.operation !== "CUT" || cmd.sheetId !== this.state?.sheetId) {
return;
}
const isClipboardDirty = this.isColRowDirtyingClipboard(
Expand All @@ -143,7 +143,7 @@ export class ClipboardPlugin extends UIPlugin {
this.status = "invisible";

// If we remove a col/row inside or before the cut area, we invalidate the clipboard
if (this.state?.operation !== "CUT") {
if (this.state?.operation !== "CUT" || cmd.sheetId !== this.state?.sheetId) {
return;
}
for (let el of cmd.elements) {
Expand Down
28 changes: 28 additions & 0 deletions tests/plugins/clipboard.test.ts
Expand Up @@ -1598,6 +1598,20 @@ describe("clipboard: pasting outside of sheet", () => {
expect(getCellContent(model, "C1")).toBe("");
expect(getCellContent(model, "C3")).toBe("");
});

test("Adding rows in another sheet does not invalidate the clipboard", () => {
const model = new Model();
setCellContent(model, "A1", "1");
setCellContent(model, "A2", "2");
model.dispatch("CUT", { target: target("A1:A2") });

createSheet(model, { activate: true });
addRows(model, "after", 0, 5);

model.dispatch("PASTE", { target: target("A1") });
expect(getCellContent(model, "A1")).toBe("1");
expect(getCellContent(model, "A2")).toBe("2");
});
});

describe("remove col/row can invalidate the clipboard of cut", () => {
Expand Down Expand Up @@ -1680,5 +1694,19 @@ describe("clipboard: pasting outside of sheet", () => {
expect(getCellContent(model, "B2")).toBe("1");
expect(getCellContent(model, "D1")).toBe("");
});

test("Removing rows in another sheet does not invalidate the clipboard", () => {
const model = new Model();
setCellContent(model, "A1", "1");
setCellContent(model, "A2", "2");
model.dispatch("CUT", { target: target("A1:A2") });

createSheet(model, { activate: true });
deleteRows(model, [1]);

model.dispatch("PASTE", { target: target("A1") });
expect(getCellContent(model, "A1")).toBe("1");
expect(getCellContent(model, "A2")).toBe("2");
});
});
});

0 comments on commit f4034dd

Please sign in to comment.