Skip to content

Commit 41a7678

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 #7291 Task: 5156459 Signed-off-by: Rémi Rahir (rar) <rar@odoo.com>
1 parent 4bf3363 commit 41a7678

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
@@ -237,7 +237,7 @@ export class CellClipboardHandler extends AbstractCellClipboardHandler<
237237
) {
238238
const { sheetId, col, row } = target;
239239
const targetCell = this.getters.getEvaluatedCell(target);
240-
const originFormat = origin?.format ?? origin.evaluatedCell.format;
240+
const originFormat = origin?.format || origin.evaluatedCell.format;
241241

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

tests/clipboard/clipboard_plugin.test.ts

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

1286+
test("paste as value works with both no core format and empty string core format", () => {
1287+
const model = new Model();
1288+
setCellContent(model, "D4", "=DATE(2024,6,5)");
1289+
1290+
copy(model, "D4");
1291+
paste(model, "E4", "asValue");
1292+
expect(getCell(model, "E4")).toMatchObject({ content: "45448", format: "m/d/yyyy" });
1293+
1294+
setFormat(model, "D4", ""); // An empty string format is equivalent to no format
1295+
expect(getCellContent(model, "D4")).toBe("6/5/2024");
1296+
1297+
copy(model, "D4");
1298+
paste(model, "E5", "asValue");
1299+
expect(getCell(model, "E5")).toMatchObject({ content: "45448", format: "m/d/yyyy" });
1300+
});
1301+
12861302
test("can copy a formula and paste as value", () => {
12871303
const model = new Model();
12881304
setCellContent(model, "A1", "=SUM(1+2)");

0 commit comments

Comments
 (0)