Skip to content

Commit a22fede

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 #4234 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 f8e0444 commit a22fede

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

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

203203
// If we remove a col/row inside or before the cut area, we invalidate the clipboard
204-
if (this.state?.operation !== "CUT") {
204+
if (this.state?.operation !== "CUT" || cmd.sheetId !== this.state?.sheetId) {
205205
return;
206206
}
207207
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
@@ -2261,6 +2261,20 @@ describe("clipboard: pasting outside of sheet", () => {
22612261
expect(getCellContent(model, "C1")).toBe("");
22622262
expect(getCellContent(model, "C3")).toBe("");
22632263
});
2264+
2265+
test("Adding rows in another sheet does not invalidate the clipboard", () => {
2266+
const model = new Model();
2267+
setCellContent(model, "A1", "1");
2268+
setCellContent(model, "A2", "2");
2269+
cut(model, "A1:A2");
2270+
2271+
createSheet(model, { activate: true });
2272+
addRows(model, "after", 0, 5);
2273+
2274+
paste(model, "A1");
2275+
expect(getCellContent(model, "A1")).toBe("1");
2276+
expect(getCellContent(model, "A2")).toBe("2");
2277+
});
22642278
});
22652279

22662280
describe("remove col/row can invalidate the clipboard of cut", () => {
@@ -2343,5 +2357,19 @@ describe("clipboard: pasting outside of sheet", () => {
23432357
expect(getCellContent(model, "B2")).toBe("1");
23442358
expect(getCellContent(model, "D1")).toBe("");
23452359
});
2360+
2361+
test("Removing rows in another sheet does not invalidate the clipboard", () => {
2362+
const model = new Model();
2363+
setCellContent(model, "A1", "1");
2364+
setCellContent(model, "A2", "2");
2365+
cut(model, "A1:A2");
2366+
2367+
createSheet(model, { activate: true });
2368+
deleteRows(model, [1]);
2369+
2370+
paste(model, "A1");
2371+
expect(getCellContent(model, "A1")).toBe("1");
2372+
expect(getCellContent(model, "A2")).toBe("2");
2373+
});
23462374
});
23472375
});

0 commit comments

Comments
 (0)