fix: support multiline

This commit is contained in:
Daniel
2025-12-06 23:06:49 +01:00
parent d8329676ca
commit 80a48cef27

View File

@@ -154,34 +154,43 @@ const Workbook = (props: { model: Model; workbookState: WorkbookState }) => {
row: number; row: number;
oldFontSize: number; oldFontSize: number;
oldRowHeight: number; oldRowHeight: number;
maxLineCount: number;
}> = []; }> = [];
for (let row = actualRowStart; row <= actualRowEnd; row++) { for (let row = actualRowStart; row <= actualRowEnd; row++) {
let maxFontSize = 0; let maxFontSize = 0;
let maxLineCount = 1;
for (let col = actualColumnStart; col <= actualColumnEnd; col++) { for (let col = actualColumnStart; col <= actualColumnEnd; col++) {
const style = model.getCellStyle(sheet, row, col); const style = model.getCellStyle(sheet, row, col);
maxFontSize = Math.max(maxFontSize, style.font.sz); 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); const oldRowHeight = model.getRowHeight(sheet, row);
rowData.push({ rowData.push({
row, row,
oldFontSize: maxFontSize, oldFontSize: maxFontSize,
oldRowHeight, oldRowHeight,
maxLineCount,
}); });
} }
/** Update the font size in the model */ /** Update the font size in the model */
updateRangeStyle("font.size_delta", `${delta}`); updateRangeStyle("font.size_delta", `${delta}`);
/** Adjust row heights based on the new font sizes */ /** Adjust row heights based on the new font sizes and line counts */
for (const { row, oldFontSize, oldRowHeight } of rowData) { for (const { row, oldFontSize, oldRowHeight, maxLineCount } of rowData) {
const newFontSize = oldFontSize + delta; const newFontSize = oldFontSize + delta;
if (oldRowHeight < DEFAULT_ROW_HEIGHT) { if (oldRowHeight < DEFAULT_ROW_HEIGHT) {
continue; continue;
} }
const requiredHeight = 8 + newFontSize; const lineHeight = newFontSize * 1.5;
const requiredHeight = (maxLineCount - 1) * lineHeight + 8 + newFontSize;
let newRowHeight: number; let newRowHeight: number;
if (requiredHeight > DEFAULT_ROW_HEIGHT) { if (requiredHeight > DEFAULT_ROW_HEIGHT) {