Skip to content

Commit 9592a2f

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 #4237 Task: 3901961 X-original-commit: cfb3a65 Signed-off-by: Lucas Lefèvre (lul) <[email protected]> Signed-off-by: Adrien Minne (adrm) <[email protected]>
1 parent 4074130 commit 9592a2f

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
@@ -210,7 +210,7 @@ export class ClipboardPlugin extends UIPlugin {
210210
this.status = "invisible";
211211

212212
// If we add a col/row inside or before the cut area, we invalidate the clipboard
213-
if (this._isCutOperation !== true) {
213+
if (this._isCutOperation !== true || cmd.sheetId !== this.copiedData?.sheetId) {
214214
return;
215215
}
216216
const isClipboardDirty = this.isColRowDirtyingClipboard(
@@ -226,7 +226,7 @@ export class ClipboardPlugin extends UIPlugin {
226226
this.status = "invisible";
227227

228228
// If we remove a col/row inside or before the cut area, we invalidate the clipboard
229-
if (this._isCutOperation !== true) {
229+
if (this._isCutOperation !== true || cmd.sheetId !== this.copiedData?.sheetId) {
230230
return;
231231
}
232232
for (let el of cmd.elements) {

tests/clipboard/clipboard_plugin.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2188,6 +2188,20 @@ describe("clipboard: pasting outside of sheet", () => {
21882188
expect(getCellContent(model, "C1")).toBe("");
21892189
expect(getCellContent(model, "C3")).toBe("");
21902190
});
2191+
2192+
test("Adding rows in another sheet does not invalidate the clipboard", () => {
2193+
const model = new Model();
2194+
setCellContent(model, "A1", "1");
2195+
setCellContent(model, "A2", "2");
2196+
cut(model, "A1:A2");
2197+
2198+
createSheet(model, { activate: true });
2199+
addRows(model, "after", 0, 5);
2200+
2201+
paste(model, "A1");
2202+
expect(getCellContent(model, "A1")).toBe("1");
2203+
expect(getCellContent(model, "A2")).toBe("2");
2204+
});
21912205
});
21922206

21932207
describe("remove col/row can invalidate the clipboard of cut", () => {
@@ -2270,5 +2284,19 @@ describe("clipboard: pasting outside of sheet", () => {
22702284
expect(getCellContent(model, "B2")).toBe("1");
22712285
expect(getCellContent(model, "D1")).toBe("");
22722286
});
2287+
2288+
test("Removing rows in another sheet does not invalidate the clipboard", () => {
2289+
const model = new Model();
2290+
setCellContent(model, "A1", "1");
2291+
setCellContent(model, "A2", "2");
2292+
cut(model, "A1:A2");
2293+
2294+
createSheet(model, { activate: true });
2295+
deleteRows(model, [1]);
2296+
2297+
paste(model, "A1");
2298+
expect(getCellContent(model, "A1")).toBe("1");
2299+
expect(getCellContent(model, "A2")).toBe("2");
2300+
});
22732301
});
22742302
});

0 commit comments

Comments
 (0)