Skip to content

Commit cfb3a65

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 #4236 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 4c4a7eb commit cfb3a65

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
@@ -2175,6 +2175,20 @@ describe("clipboard: pasting outside of sheet", () => {
21752175
expect(getCellContent(model, "C1")).toBe("");
21762176
expect(getCellContent(model, "C3")).toBe("");
21772177
});
2178+
2179+
test("Adding rows in another sheet does not invalidate the clipboard", () => {
2180+
const model = new Model();
2181+
setCellContent(model, "A1", "1");
2182+
setCellContent(model, "A2", "2");
2183+
cut(model, "A1:A2");
2184+
2185+
createSheet(model, { activate: true });
2186+
addRows(model, "after", 0, 5);
2187+
2188+
paste(model, "A1");
2189+
expect(getCellContent(model, "A1")).toBe("1");
2190+
expect(getCellContent(model, "A2")).toBe("2");
2191+
});
21782192
});
21792193

21802194
describe("remove col/row can invalidate the clipboard of cut", () => {
@@ -2257,5 +2271,19 @@ describe("clipboard: pasting outside of sheet", () => {
22572271
expect(getCellContent(model, "B2")).toBe("1");
22582272
expect(getCellContent(model, "D1")).toBe("");
22592273
});
2274+
2275+
test("Removing rows in another sheet does not invalidate the clipboard", () => {
2276+
const model = new Model();
2277+
setCellContent(model, "A1", "1");
2278+
setCellContent(model, "A2", "2");
2279+
cut(model, "A1:A2");
2280+
2281+
createSheet(model, { activate: true });
2282+
deleteRows(model, [1]);
2283+
2284+
paste(model, "A1");
2285+
expect(getCellContent(model, "A1")).toBe("1");
2286+
expect(getCellContent(model, "A2")).toBe("2");
2287+
});
22602288
});
22612289
});

0 commit comments

Comments
 (0)