Skip to content

Commit 1d848dc

Browse files
committed
[FIX] clipboard: paste as value with empty format string
Our paste as value keeps the format from the origin cell, removing only the formula. But if the origin cell had an empty format string, it would copy this empty string instead of the evaluated cell format. Note: we get empty string format as result of, for example, auto-fill an `=TODAY()` formula. It can be argued that we should have `undefined` core format rather than an empty string, but every other place in the codebase handles all falsy format values the same way. The clipboard was the only place where we would make the distinction between `""` and `undefined` with `??`. closes #7339 Task: 5156459 X-original-commit: 41a7678 Signed-off-by: Rémi Rahir (rar) <rar@odoo.com>
1 parent ebb2d54 commit 1d848dc

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/clipboard_handlers/cell_clipboard.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ export class CellClipboardHandler extends AbstractCellClipboardHandler<
238238
) {
239239
const { sheetId, col, row } = target;
240240
const targetCell = this.getters.getEvaluatedCell(target);
241-
const originFormat = origin?.format ?? origin.evaluatedCell.format;
241+
const originFormat = origin?.format || origin.evaluatedCell.format;
242242

243243
if (clipboardOption?.pasteOption === "asValue") {
244244
this.dispatch("UPDATE_CELL", {

tests/clipboard/clipboard_plugin.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,6 +1293,22 @@ describe("clipboard", () => {
12931293
expect(getCellContent(model, "C3")).toBe("45.10%");
12941294
});
12951295

1296+
test("paste as value works with both no core format and empty string core format", () => {
1297+
const model = new Model();
1298+
setCellContent(model, "D4", "=DATE(2024,6,5)");
1299+
1300+
copy(model, "D4");
1301+
paste(model, "E4", "asValue");
1302+
expect(getCell(model, "E4")).toMatchObject({ content: "45448", format: "m/d/yyyy" });
1303+
1304+
setFormat(model, "D4", ""); // An empty string format is equivalent to no format
1305+
expect(getCellContent(model, "D4")).toBe("6/5/2024");
1306+
1307+
copy(model, "D4");
1308+
paste(model, "E5", "asValue");
1309+
expect(getCell(model, "E5")).toMatchObject({ content: "45448", format: "m/d/yyyy" });
1310+
});
1311+
12961312
test("can copy a formula and paste as value", () => {
12971313
const model = new Model();
12981314
setCellContent(model, "A1", "=SUM(1+2)");

0 commit comments

Comments
 (0)