Skip to content

Commit dad00f0

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 #4235 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 2fba76e commit dad00f0

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
@@ -2190,6 +2190,20 @@ describe("clipboard: pasting outside of sheet", () => {
21902190
expect(getCellContent(model, "C1")).toBe("");
21912191
expect(getCellContent(model, "C3")).toBe("");
21922192
});
2193+
2194+
test("Adding rows in another sheet does not invalidate the clipboard", () => {
2195+
const model = new Model();
2196+
setCellContent(model, "A1", "1");
2197+
setCellContent(model, "A2", "2");
2198+
cut(model, "A1:A2");
2199+
2200+
createSheet(model, { activate: true });
2201+
addRows(model, "after", 0, 5);
2202+
2203+
paste(model, "A1");
2204+
expect(getCellContent(model, "A1")).toBe("1");
2205+
expect(getCellContent(model, "A2")).toBe("2");
2206+
});
21932207
});
21942208

21952209
describe("remove col/row can invalidate the clipboard of cut", () => {
@@ -2272,5 +2286,19 @@ describe("clipboard: pasting outside of sheet", () => {
22722286
expect(getCellContent(model, "B2")).toBe("1");
22732287
expect(getCellContent(model, "D1")).toBe("");
22742288
});
2289+
2290+
test("Removing rows in another sheet does not invalidate the clipboard", () => {
2291+
const model = new Model();
2292+
setCellContent(model, "A1", "1");
2293+
setCellContent(model, "A2", "2");
2294+
cut(model, "A1:A2");
2295+
2296+
createSheet(model, { activate: true });
2297+
deleteRows(model, [1]);
2298+
2299+
paste(model, "A1");
2300+
expect(getCellContent(model, "A1")).toBe("1");
2301+
expect(getCellContent(model, "A2")).toBe("2");
2302+
});
22752303
});
22762304
});

0 commit comments

Comments
 (0)