Skip to content

Commit 918006e

Browse files
matho-odoorrahir
authored andcommitted
[FIX] clipboard : paste as value
The format should not be pasted closes #8124 Task: 5936382 X-original-commit: 1198bbd Signed-off-by: Rémi Rahir (rar) <rar@odoo.com>
1 parent f541294 commit 918006e

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

src/clipboard_handlers/cell_clipboard.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,6 @@ export class CellClipboardHandler extends AbstractCellClipboardHandler<
243243
this.dispatch("UPDATE_CELL", {
244244
...target,
245245
content: origin.evaluatedCell.value?.toString() || "",
246-
format: originFormat,
247246
});
248247
return;
249248
}

tests/clipboard/clipboard_plugin.test.ts

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,7 +1267,7 @@ describe("clipboard", () => {
12671267
expect(getBorder(model, "C4")).toBeNull();
12681268
});
12691269

1270-
test("paste as value does not remove number format", () => {
1270+
test("paste as value does remove number format", () => {
12711271
const model = new Model();
12721272
setCellContent(model, "B2", "0.451");
12731273
setFormat(model, "B2", "0.00%");
@@ -1279,7 +1279,7 @@ describe("clipboard", () => {
12791279

12801280
copy(model, "B2");
12811281
paste(model, "C3", "asValue");
1282-
expect(getCellContent(model, "C3")).toBe("45.10%");
1282+
expect(getCellContent(model, "C3")).toBe("0.45");
12831283
});
12841284

12851285
test("paste as value works with both no core format and empty string core format", () => {
@@ -1288,14 +1288,49 @@ describe("clipboard", () => {
12881288

12891289
copy(model, "D4");
12901290
paste(model, "E4", "asValue");
1291-
expect(getCell(model, "E4")).toMatchObject({ content: "45448", format: "m/d/yyyy" });
1291+
expect(getCell(model, "E4")).toMatchObject({ content: "45448", format: undefined });
12921292

12931293
setFormat(model, "D4", ""); // An empty string format is equivalent to no format
12941294
expect(getCellContent(model, "D4")).toBe("6/5/2024");
12951295

12961296
copy(model, "D4");
12971297
paste(model, "E5", "asValue");
1298-
expect(getCell(model, "E5")).toMatchObject({ content: "45448", format: "m/d/yyyy" });
1298+
expect(getCell(model, "E5")).toMatchObject({ content: "45448", format: undefined });
1299+
});
1300+
1301+
test.each([
1302+
["1", "0.00%", "100.00%"],
1303+
["46023", "m/d/yyyy", "1/1/2026"],
1304+
])(
1305+
"can copy a cell with a format and paste as value",
1306+
(originalContent, format, formatedContent) => {
1307+
const model = new Model();
1308+
setCellContent(model, "B2", originalContent);
1309+
setFormat(model, "B2", format);
1310+
expect(getCellContent(model, "B2")).toBe(formatedContent);
1311+
expect(getCell(model, "B2")!.format).toEqual(format);
1312+
1313+
copy(model, "B2");
1314+
paste(model, "C2", "asValue");
1315+
1316+
expect(getCellContent(model, "C2")).toBe(originalContent);
1317+
expect(getCell(model, "C2")!.format).not.toBeDefined();
1318+
}
1319+
);
1320+
1321+
test("copy as value : the cell take the format of the target cell", () => {
1322+
const model = new Model();
1323+
setCellContent(model, "B2", "46023");
1324+
setFormat(model, "B2", "0.00%");
1325+
expect(getCellContent(model, "B2")).toBe("4602300.00%");
1326+
expect(getCell(model, "B2")!.format).toEqual("0.00%");
1327+
1328+
setFormat(model, "C2", "m/d/yyyy");
1329+
copy(model, "B2");
1330+
paste(model, "C2", "asValue");
1331+
1332+
expect(getCellContent(model, "C2")).toBe("1/1/2026");
1333+
expect(getCell(model, "C2")!.format).toEqual("m/d/yyyy");
12991334
});
13001335

13011336
test("can copy a formula and paste as value", () => {

0 commit comments

Comments
 (0)