Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sheet): support read default style when create editor #4540

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions packages/core/src/sheets/worksheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,24 @@ export class Worksheet {
return this._styles.get(style);
}

/**
* Get the default style for cell.
* @param {number} row The row index.
* @param {number} col The column index.
* @param {boolean} [isRowStylePrecedeColumnStyle] The priority of row style and column style
* @returns {Nullable<IStyleData>} The default style for cell
*/
getCellDefaultStyle(row: number, col: number, isRowStylePrecedeColumnStyle?: boolean): Nullable<IStyleData> {
const columnStyle = this.getColumnStyle(col) as Nullable<IStyleData>;
const rowStyle = this.getRowStyle(row) as Nullable<IStyleData>;
const defaultStyle = this.getDefaultCellStyleInternal();
if (isRowStylePrecedeColumnStyle) {
return composeStyles(defaultStyle, rowStyle, columnStyle);
} else {
return composeStyles(defaultStyle, columnStyle, rowStyle);
}
}

/**
* Set Default Style, if the style has been set, all cells style will be base on this style.
* @param {Nullable<IStyleData>} style The style to be set as default style
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ interface ICellDocumentModelOption {
isDeepClone?: boolean;
displayRawFormula?: boolean;
ignoreTextRotation?: boolean;
cellDefaultStyle?: Nullable<IStyleData>;
}

const DEFAULT_CELL_DOCUMENT_MODEL_OPTION: ICellDocumentModelOption = {
Expand Down Expand Up @@ -849,11 +850,12 @@ export class SpreadsheetSkeleton extends SheetSkeleton {
* @deprecated use same method in worksheet.
* @param cell
*/
getCellDocumentModelWithFormula(cell: ICellData): Nullable<IDocumentLayoutObject> {
getCellDocumentModelWithFormula(cell: ICellData, cellDefaultStyle: Nullable<IStyleData>): Nullable<IDocumentLayoutObject> {
return this._getCellDocumentModel(cell, {
isDeepClone: true,
displayRawFormula: true,
ignoreTextRotation: true,
cellDefaultStyle,
});
}

Expand All @@ -876,7 +878,7 @@ export class SpreadsheetSkeleton extends SheetSkeleton {
...options,
};

const style = this._styles.getStyleByCell(cell);
const style = { ...options.cellDefaultStyle, ...this._styles.getStyleByCell(cell) };

if (!cell) return;

Expand Down
3 changes: 2 additions & 1 deletion packages/sheets-ui/src/services/editor-bridge.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,9 @@ export class EditorBridgeService extends Disposable implements IEditorBridgeServ
worksheet.getCell(startRow, startColumn),
location
);
const cellDefaultStyle = worksheet.getCellDefaultStyle(startRow, startColumn, skeleton.isRowStylePrecedeColumnStyle);

documentLayoutObject = cell && skeleton.getCellDocumentModelWithFormula(cell);
documentLayoutObject = cell && skeleton.getCellDocumentModelWithFormula(cell, cellDefaultStyle);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the only place that cellDefaultStyle should be passed? getCellDocumentModelWithFormula are called in other situations such as removing cell hyperlink.


// Rewrite the cellValueType to STRING to avoid render the value on the right side when number type.
const renderConfig = documentLayoutObject?.documentModel?.documentStyle.renderConfig;
Expand Down
Loading