Skip to content

Commit 3e47e44

Browse files
committed
[FIX] grid_renderer_store: keep wrapping width with explicit align
Since PR#8004 ([FIX] Dynamic pivot: header alignment), width-aware formatting is disabled on explicitly aligned cells to preserve the pivot header alignment fix. The renderer was reusing that same width to split wrapped content, so cells with `wrapping: "wrap"` and an explicit horizontal alignment were still getting the correct row height, but their text was rendered as a single clipped line. This commit separates the formatting width from the wrapping width: - keep `formatWidth` disabled for explicitly aligned cells - always use the real cell width to split wrapped text closes #8216 Task: 6032407 X-original-commit: c39fdd0 Signed-off-by: Rémi Rahir (rar) <rar@odoo.com> Signed-off-by: Dhrutik Patel (dhrp) <dhrp@odoo.com>
1 parent ae7001a commit 3e47e44

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

packages/o-spreadsheet-engine/src/plugins/ui_feature/ui_sheet.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,14 @@ export class SheetUIPlugin extends UIPlugin {
162162
*/
163163
getCellMultiLineText(
164164
position: CellPosition,
165-
args: { wrapText: boolean; maxWidth: number }
165+
// Keep the stable getter signature additive for compatibility.
166+
// 19.3+ can use a dedicated wrapping width argument instead.
167+
args: { wrapText: boolean; maxWidth: number; formatWidth?: number }
166168
): string[] {
167169
const style = this.getters.getCellStyle(position);
168170
const text = this.getters.getCellText(position, {
169171
showFormula: this.getters.shouldShowFormulas(),
170-
availableWidth: args.maxWidth,
172+
availableWidth: args.formatWidth,
171173
});
172174
return splitTextToWidth(this.ctx, text, style, args.wrapText ? args.maxWidth : undefined);
173175
}

src/stores/grid_renderer_store.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -742,9 +742,13 @@ export class GridRenderer extends SpreadsheetStore {
742742
/** Content */
743743
const wrapping = style.wrapping || "overflow";
744744
const wrapText = wrapping === "wrap" && !showFormula;
745-
// we want to give priority to the style, so if there is one we don't fill with white spaces
746-
const maxWidth = style.align ? 0 : width - 2 * MIN_CELL_TEXT_MARGIN;
747-
const multiLineText = this.getters.getCellMultiLineText(position, { maxWidth, wrapText });
745+
const maxWidth = width - 2 * MIN_CELL_TEXT_MARGIN;
746+
const formatWidth = style.align ? 0 : maxWidth;
747+
const multiLineText = this.getters.getCellMultiLineText(position, {
748+
maxWidth,
749+
formatWidth,
750+
wrapText,
751+
});
748752
const noRotatationStyle = { ...style, align: "left" as const, rotation: 0 };
749753
const textWidth =
750754
Math.max(...multiLineText.map((line) => this.getters.getTextWidth(line, noRotatationStyle))) +

tests/renderer/renderer_store.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1976,6 +1976,23 @@ describe("renderer", () => {
19761976
expect(renderedTexts.slice(0, 4)).toEqual(splittedText);
19771977
});
19781978

1979+
test.each<Align>(["left", "center", "right"])(
1980+
"Wrapped text is displayed over multiple lines with %s align",
1981+
(align) => {
1982+
const overFlowingContent = "ThisIsAVeryVeryLongText";
1983+
setCellContent(model, "A1", overFlowingContent);
1984+
setFormatting(model, "A1", { wrapping: "wrap", align });
1985+
resizeColumns(model, ["A"], 14);
1986+
1987+
// Split length = 14 - 2*MIN_CELL_TEXT_MARGIN = 6 letters (1 letter = 1px in the tests)
1988+
const splittedText = ["ThisIs", "AVeryV", "eryLon", "gText"];
1989+
1990+
drawGridRenderer(ctx);
1991+
1992+
expect(renderedTexts.slice(0, 4)).toEqual(splittedText);
1993+
}
1994+
);
1995+
19791996
test("Wrapped text try to not split words in multiple lines if the word is small enough", () => {
19801997
const overFlowingContent = "W Word2 W3 WordThatIsTooLong";
19811998
setCellContent(model, "A1", overFlowingContent);

0 commit comments

Comments
 (0)