From c2c24a0428b32abbf9140638804a88d8e1fd6939 Mon Sep 17 00:00:00 2001 From: "Adrien Minne (adrm)" Date: Mon, 7 Oct 2024 07:00:07 +0000 Subject: [PATCH] [FIX] paint format: copy conditional formats MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The paint format tool should also copy the conditional formats of the source cells. closes odoo/o-spreadsheet#5124 Task: 4226853 X-original-commit: 4f2950a8bfaa8dac75e2071a458efa1bdb20b4d0 Signed-off-by: Lucas Lefèvre (lul) --- .../paint_format_button/paint_format_store.ts | 2 ++ tests/grid/grid_component.test.ts | 24 ++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/components/paint_format_button/paint_format_store.ts b/src/components/paint_format_button/paint_format_store.ts index f5212204f4..185d7ad963 100644 --- a/src/components/paint_format_button/paint_format_store.ts +++ b/src/components/paint_format_button/paint_format_store.ts @@ -1,6 +1,7 @@ import { ClipboardHandler } from "../../clipboard_handlers/abstract_clipboard_handler"; import { BorderClipboardHandler } from "../../clipboard_handlers/borders_clipboard"; import { CellClipboardHandler } from "../../clipboard_handlers/cell_clipboard"; +import { ConditionalFormatClipboardHandler } from "../../clipboard_handlers/conditional_format_clipboard"; import { TableClipboardHandler } from "../../clipboard_handlers/tables_clipboard"; import { SELECTION_BORDER_COLOR } from "../../constants"; import { getClipboardDataPositions } from "../../helpers/clipboard/clipboard_helpers"; @@ -23,6 +24,7 @@ export class PaintFormatStore extends SpreadsheetStore { new CellClipboardHandler(this.getters, this.model.dispatch), new BorderClipboardHandler(this.getters, this.model.dispatch), new TableClipboardHandler(this.getters, this.model.dispatch), + new ConditionalFormatClipboardHandler(this.getters, this.model.dispatch), ]; private status: "inactive" | "oneOff" | "persistent" = "inactive"; diff --git a/tests/grid/grid_component.test.ts b/tests/grid/grid_component.test.ts index dc18853a45..d4ffb3c947 100644 --- a/tests/grid/grid_component.test.ts +++ b/tests/grid/grid_component.test.ts @@ -76,7 +76,14 @@ import { getSelectionAnchorCellXc, getStyle, } from "../test_helpers/getters_helpers"; -import { mockChart, mountSpreadsheet, nextTick, typeInComposerGrid } from "../test_helpers/helpers"; +import { + createEqualCF, + mockChart, + mountSpreadsheet, + nextTick, + toRangesData, + typeInComposerGrid, +} from "../test_helpers/helpers"; import { mockGetBoundingClientRect } from "../test_helpers/mock_helpers"; jest.mock("../../src/components/composer/content_editable_helper", () => require("../__mocks__/content_editable_helper") @@ -881,6 +888,21 @@ describe("Grid component", () => { expect(getCell(model, "C8")?.style).toMatchObject({ fillColor: "#748747" }); }); + test("Paste format works with conditional format", () => { + const sheetId = model.getters.getActiveSheetId(); + model.dispatch("ADD_CONDITIONAL_FORMAT", { + cf: createEqualCF("1", { fillColor: "#0000FF" }, "cf2"), + sheetId, + ranges: toRangesData(sheetId, "A1"), + }); + selectCell(model, "A1"); + paintFormatStore.activate({ persistent: false }); + gridMouseEvent(model, "pointerdown", "C8"); + gridMouseEvent(model, "pointerup", "C8"); + + expect(model.getters.getConditionalFormats(sheetId)[0].ranges).toEqual(["A1", "C8"]); + }); + test("can keep the paint format mode persistently", async () => { setCellContent(model, "B2", "b2"); selectCell(model, "B2");