Skip to content

Commit d29a874

Browse files
committed
[FIX] paint format: properly paint borders and tables
Since the paint format tool was moved from the clipboard plugin to its own store, it didn't handle the borders and tables properly. This commit fixes that by adding the two ClipboardHandlers to the PaintFormatStore. closes #5034 Task: 4213894 Signed-off-by: Lucas Lefèvre (lul) <lul@odoo.com>
1 parent a006d0b commit d29a874

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

src/components/paint_format_button/paint_format_store.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
import { ClipboardHandler } from "../../clipboard_handlers/abstract_clipboard_handler";
2+
import { BorderClipboardHandler } from "../../clipboard_handlers/borders_clipboard";
13
import { CellClipboardHandler } from "../../clipboard_handlers/cell_clipboard";
4+
import { TableClipboardHandler } from "../../clipboard_handlers/tables_clipboard";
25
import { SELECTION_BORDER_COLOR } from "../../constants";
36
import { getClipboardDataPositions } from "../../helpers/clipboard/clipboard_helpers";
47
import { Get } from "../../store_engine";
@@ -16,7 +19,11 @@ export class PaintFormatStore extends SpreadsheetStore {
1619
mutators = ["activate", "cancel", "pasteFormat"] as const;
1720

1821
protected highlightStore = this.get(HighlightStore);
19-
private cellClipboardHandler = new CellClipboardHandler(this.getters, this.model.dispatch);
22+
private clipboardHandlers: ClipboardHandler<any>[] = [
23+
new CellClipboardHandler(this.getters, this.model.dispatch),
24+
new BorderClipboardHandler(this.getters, this.model.dispatch),
25+
new TableClipboardHandler(this.getters, this.model.dispatch),
26+
];
2027

2128
private status: "inactive" | "oneOff" | "persistent" = "inactive";
2229
private copiedData?: ClipboardContent;
@@ -42,10 +49,12 @@ export class PaintFormatStore extends SpreadsheetStore {
4249
pasteFormat(target: Zone[]) {
4350
if (this.copiedData) {
4451
const sheetId = this.getters.getActiveSheetId();
45-
this.cellClipboardHandler.paste({ zones: target, sheetId }, this.copiedData, {
46-
isCutOperation: false,
47-
pasteOption: "onlyFormat",
48-
});
52+
for (const handler of this.clipboardHandlers) {
53+
handler.paste({ zones: target, sheetId }, this.copiedData, {
54+
isCutOperation: false,
55+
pasteOption: "onlyFormat",
56+
});
57+
}
4958
}
5059
if (this.status === "oneOff") {
5160
this.cancel();
@@ -60,7 +69,12 @@ export class PaintFormatStore extends SpreadsheetStore {
6069
const sheetId = this.getters.getActiveSheetId();
6170
const zones = this.getters.getSelectedZones();
6271

63-
return this.cellClipboardHandler.copy(getClipboardDataPositions(sheetId, zones));
72+
const copiedData = {};
73+
for (const handler of this.clipboardHandlers) {
74+
Object.assign(copiedData, handler.copy(getClipboardDataPositions(sheetId, zones)));
75+
}
76+
77+
return copiedData as ClipboardContent;
6478
}
6579

6680
get highlights(): Highlight[] {

tests/grid/grid_component.test.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { PaintFormatStore } from "../../src/components/paint_format_button/paint
55
import { CellPopoverStore } from "../../src/components/popover";
66
import {
77
BACKGROUND_GRAY_COLOR,
8+
DEFAULT_BORDER_DESC,
89
DEFAULT_CELL_HEIGHT,
910
DEFAULT_CELL_WIDTH,
1011
GRID_ICON_EDGE_LENGTH,
@@ -40,6 +41,7 @@ import {
4041
selectColumn,
4142
selectHeader,
4243
selectRow,
44+
setBorders,
4345
setCellContent,
4446
setCellFormat,
4547
setSelection,
@@ -64,6 +66,7 @@ import {
6466
} from "../test_helpers/dom_helper";
6567
import {
6668
getActiveSheetFullScrollInfo,
69+
getBorder,
6770
getCell,
6871
getCellContent,
6972
getCellText,
@@ -849,22 +852,34 @@ describe("Grid component", () => {
849852
highlightStore = env.getStore(HighlightStore);
850853
});
851854

852-
test("can paste format with mouse once", async () => {
855+
test("can paste format and borders with mouse once", async () => {
853856
setCellContent(model, "B2", "b2");
854857
selectCell(model, "B2");
855858
setStyle(model, "B2", { bold: true });
859+
setBorders(model, "B2", { top: DEFAULT_BORDER_DESC });
856860
paintFormatStore.activate({ persistent: false });
857861
gridMouseEvent(model, "pointerdown", "C8");
858862
expect(getCell(model, "C8")).toBeUndefined();
859863
gridMouseEvent(model, "pointerup", "C8");
860864
expect(getCell(model, "C8")!.style).toEqual({ bold: true });
865+
expect(getBorder(model, "C8")).toEqual({ top: DEFAULT_BORDER_DESC });
861866

862867
gridMouseEvent(model, "pointerdown", "D8");
863868
expect(getCell(model, "D8")).toBeUndefined();
864869
gridMouseEvent(model, "pointerup", "D8");
865870
expect(getCell(model, "D8")).toBeUndefined();
866871
});
867872

873+
test("Paste format works with table style", () => {
874+
createTable(model, "A1:B2", { styleId: "TableStyleLight11" });
875+
selectCell(model, "A1");
876+
paintFormatStore.activate({ persistent: false });
877+
gridMouseEvent(model, "pointerdown", "C8");
878+
gridMouseEvent(model, "pointerup", "C8");
879+
880+
expect(getCell(model, "C8")?.style).toMatchObject({ fillColor: "#748747" });
881+
});
882+
868883
test("can keep the paint format mode persistently", async () => {
869884
setCellContent(model, "B2", "b2");
870885
selectCell(model, "B2");

0 commit comments

Comments
 (0)