Skip to content

Commit

Permalink
[FIX] header_size: prevent row resize caused by multiline formulas
Browse files Browse the repository at this point in the history
Previously, typing a formula with multiple lines (e.g. = A1 + [NEWLINE] 2)
caused the rows to resize, as the formula was displayed on two lines.
To prevent this unnecessary row resize, a hard-coded value of 1 is now
returned from `getDefaultCellHeight` in the case of formula syntax.

Task-3221078.

closes #2269

Signed-off-by: Lucas Lefèvre (lul) <[email protected]>
  • Loading branch information
dhrp-odoo authored and LucasLefevre committed Apr 5, 2023
1 parent c17bb3e commit 5032610
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/helpers/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,10 @@ export function getDefaultCellHeight(cell: Cell | undefined): Pixel {
return DEFAULT_CELL_HEIGHT;
}
const fontSize = computeTextFontSizeInPixels(cell.style);
const multiLineText = cell.content.split(NEWLINE);
return computeTextLinesHeight(fontSize, multiLineText.length) + 2 * PADDING_AUTORESIZE_VERTICAL;

// the number of lines should be computed from the formula result, but it's not evaluated at this point
const numberOfLines = cell.isFormula ? 1 : cell.content.split(NEWLINE).length;
return computeTextLinesHeight(fontSize, numberOfLines) + 2 * PADDING_AUTORESIZE_VERTICAL;
}

export function computeTextWidth(context: CanvasRenderingContext2D, text: string, style: Style) {
Expand Down
7 changes: 7 additions & 0 deletions tests/plugins/formatting.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -561,4 +561,11 @@ describe("Autoresize", () => {
model.dispatch("AUTORESIZE_COLUMNS", { sheetId, cols: [0] });
expect(model.getters.getColSize(sheetId, 0)).toBe(initialSize);
});

test("row height does not take into account line breaks in the formula", async () => {
const initialSize = model.getters.getRowSize(sheetId, 0);
setCellContent(model, "A1", "=5\n\n-3\n\n-9");
expect(getCellContent(model, "A1")).toEqual("-7");
expect(model.getters.getRowSize(sheetId, 0)).toEqual(initialSize);
});
});

0 comments on commit 5032610

Please sign in to comment.