fix: support multiline
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user