Skip to content

Commit c1f0c3f

Browse files
committed
[FIX] clipboard: wrong clipboard invalidation
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 #4232 Task: 3901961 X-original-commit: ae31d65 Signed-off-by: Lucas Lefèvre (lul) <[email protected]> Signed-off-by: Adrien Minne (adrm) <[email protected]>
1 parent 4903083 commit c1f0c3f

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/plugins/ui_stateful/clipboard.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export class ClipboardPlugin extends UIPlugin {
126126
this.status = "invisible";
127127

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

144144
// If we remove a col/row inside or before the cut area, we invalidate the clipboard
145-
if (this.state?.operation !== "CUT") {
145+
if (this.state?.operation !== "CUT" || cmd.sheetId !== this.state?.sheetId) {
146146
return;
147147
}
148148
for (let el of cmd.elements) {

tests/plugins/clipboard.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2007,6 +2007,20 @@ describe("clipboard: pasting outside of sheet", () => {
20072007
expect(getCellContent(model, "C1")).toBe("");
20082008
expect(getCellContent(model, "C3")).toBe("");
20092009
});
2010+
2011+
test("Adding rows in another sheet does not invalidate the clipboard", () => {
2012+
const model = new Model();
2013+
setCellContent(model, "A1", "1");
2014+
setCellContent(model, "A2", "2");
2015+
cut(model, "A1:A2");
2016+
2017+
createSheet(model, { activate: true });
2018+
addRows(model, "after", 0, 5);
2019+
2020+
paste(model, "A1");
2021+
expect(getCellContent(model, "A1")).toBe("1");
2022+
expect(getCellContent(model, "A2")).toBe("2");
2023+
});
20102024
});
20112025

20122026
describe("remove col/row can invalidate the clipboard of cut", () => {
@@ -2089,5 +2103,19 @@ describe("clipboard: pasting outside of sheet", () => {
20892103
expect(getCellContent(model, "B2")).toBe("1");
20902104
expect(getCellContent(model, "D1")).toBe("");
20912105
});
2106+
2107+
test("Removing rows in another sheet does not invalidate the clipboard", () => {
2108+
const model = new Model();
2109+
setCellContent(model, "A1", "1");
2110+
setCellContent(model, "A2", "2");
2111+
cut(model, "A1:A2");
2112+
2113+
createSheet(model, { activate: true });
2114+
deleteRows(model, [1]);
2115+
2116+
paste(model, "A1");
2117+
expect(getCellContent(model, "A1")).toBe("1");
2118+
expect(getCellContent(model, "A2")).toBe("2");
2119+
});
20922120
});
20932121
});

0 commit comments

Comments
 (0)