Skip to content

Commit

Permalink
fix: auto height is not work when at default column width (#1840)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jocs committed Apr 10, 2024
1 parent 2002fdf commit 55e0869
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
42 changes: 32 additions & 10 deletions packages/engine-render/src/components/sheets/sheet-skeleton.ts
Expand Up @@ -168,6 +168,18 @@ interface ICellOtherConfig {
cellValueType?: CellValueType;
}

interface ICellDocumentModelOption {
isDeepClone?: boolean;
displayRawFormula?: boolean;
ignoreTextRotation?: boolean;
}

const DEFAULT_CELL_DOCUMENT_MODEL_OPTION: ICellDocumentModelOption = {
isDeepClone: false,
displayRawFormula: false,
ignoreTextRotation: false,
};

interface IRowColumnSegment {
startRow: number;
endRow: number;
Expand Down Expand Up @@ -443,8 +455,7 @@ export class SpreadsheetSkeleton extends Skeleton {

// TODO: auto height
private _calculateRowAutoHeight(rowNum: number): number {
const { columnCount, columnData, mergeData, defaultRowHeight } = this._config;
const data = columnData;
const { columnCount, columnData, mergeData, defaultRowHeight, defaultColumnWidth } = this._config;
let height = defaultRowHeight;

const worksheet = this._worksheet;
Expand All @@ -471,7 +482,7 @@ export class SpreadsheetSkeleton extends Skeleton {
continue;
}

const { documentModel, textRotation, wrapStrategy, paddingData } = modelObject;
const { documentModel, textRotation, wrapStrategy } = modelObject;
if (documentModel == null) {
continue;
}
Expand All @@ -480,7 +491,7 @@ export class SpreadsheetSkeleton extends Skeleton {

const { vertexAngle: angle } = convertTextRotation(textRotation);

const colWidth = data[i]?.w;
const colWidth = columnData[i]?.w ?? defaultColumnWidth;
if (typeof colWidth === 'number' && wrapStrategy === WrapStrategy.WRAP) {
documentModel.updateDocumentDataPageSize(colWidth);
}
Expand Down Expand Up @@ -1011,7 +1022,9 @@ export class SpreadsheetSkeleton extends Skeleton {

// Only used for cell edit, and no need to rotate text when edit cell content!
getBlankCellDocumentModel(cell: Nullable<ICellData>): IDocumentLayoutObject {
const documentModelObject = this._getCellDocumentModel(cell, undefined, undefined, true);
const documentModelObject = this._getCellDocumentModel(cell, {
ignoreTextRotation: true,
});

if (documentModelObject != null) {
if (documentModelObject.documentModel == null) {
Expand Down Expand Up @@ -1047,15 +1060,22 @@ export class SpreadsheetSkeleton extends Skeleton {

// Only used for cell edit, and no need to rotate text when edit cell content!
getCellDocumentModelWithFormula(cell: ICellData) {
return this._getCellDocumentModel(cell, true, true, true);
return this._getCellDocumentModel(cell, {
isDeepClone: true,
displayRawFormula: true,
ignoreTextRotation: true,
});
}

private _getCellDocumentModel(
cell: Nullable<ICellData>,
isDeepClone: boolean = false,
displayRawFormula: boolean = false,
ignoreTextRotation: boolean = false
options: ICellDocumentModelOption = DEFAULT_CELL_DOCUMENT_MODEL_OPTION
): Nullable<IDocumentLayoutObject> {
const { isDeepClone, displayRawFormula, ignoreTextRotation } = {
...DEFAULT_CELL_DOCUMENT_MODEL_OPTION,
...options,
};

const style = this._styles.getStyleByCell(cell);

if (!cell) {
Expand Down Expand Up @@ -1697,7 +1717,9 @@ export class SpreadsheetSkeleton extends Skeleton {
return;
}

const modelObject = cell && this._getCellDocumentModel(cell, undefined, this._renderRawFormula);
const modelObject = cell && this._getCellDocumentModel(cell, {
displayRawFormula: this._renderRawFormula,
});
if (modelObject == null) {
return;
}
Expand Down
Expand Up @@ -244,9 +244,7 @@ export class StartEditController extends Disposable {
}

offsetTop /= scaleY;

offsetTop = offsetTop < (paddingData.t || 0) ? paddingData.t || 0 : offsetTop;

documentDataModel.updateDocumentDataMargin({
t: offsetTop,
});
Expand Down

0 comments on commit 55e0869

Please sign in to comment.