From 80a48cef2745f4a424cb87272a1e5b8f0b2556de Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 6 Dec 2025 23:06:49 +0100 Subject: [PATCH] fix: support multiline --- .../IronCalc/src/components/Workbook/Workbook.tsx | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/webapp/IronCalc/src/components/Workbook/Workbook.tsx b/webapp/IronCalc/src/components/Workbook/Workbook.tsx index 7829649..31c9e7d 100644 --- a/webapp/IronCalc/src/components/Workbook/Workbook.tsx +++ b/webapp/IronCalc/src/components/Workbook/Workbook.tsx @@ -154,34 +154,43 @@ const Workbook = (props: { model: Model; workbookState: WorkbookState }) => { row: number; oldFontSize: number; oldRowHeight: number; + maxLineCount: number; }> = []; for (let row = actualRowStart; row <= actualRowEnd; row++) { let maxFontSize = 0; + let maxLineCount = 1; for (let col = actualColumnStart; col <= actualColumnEnd; col++) { const style = model.getCellStyle(sheet, row, col); maxFontSize = Math.max(maxFontSize, style.font.sz); + + // Count lines in cell content (we add new lines with Alt+Enter / Option+Enter) + const cellContent = model.getCellContent(sheet, row, col); + const lineCount = cellContent.split("\n").length; + maxLineCount = Math.max(maxLineCount, lineCount); } const oldRowHeight = model.getRowHeight(sheet, row); rowData.push({ row, oldFontSize: maxFontSize, oldRowHeight, + maxLineCount, }); } /** Update the font size in the model */ updateRangeStyle("font.size_delta", `${delta}`); - /** Adjust row heights based on the new font sizes */ - for (const { row, oldFontSize, oldRowHeight } of rowData) { + /** Adjust row heights based on the new font sizes and line counts */ + for (const { row, oldFontSize, oldRowHeight, maxLineCount } of rowData) { const newFontSize = oldFontSize + delta; if (oldRowHeight < DEFAULT_ROW_HEIGHT) { continue; } - const requiredHeight = 8 + newFontSize; + const lineHeight = newFontSize * 1.5; + const requiredHeight = (maxLineCount - 1) * lineHeight + 8 + newFontSize; let newRowHeight: number; if (requiredHeight > DEFAULT_ROW_HEIGHT) {