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(conditional-formatting): the style that involves conditional formatting does not fall #4195

Merged
merged 1 commit into from
Nov 30, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/

import {
BuildTextUtils,
Disposable,
Inject,
toDisposable,
Expand Down Expand Up @@ -45,21 +44,29 @@ export class ConditionalFormattingEditorController extends Disposable {
AFTER_CELL_EDIT,
{
handler: (value, context, next) => {
if (!value) {
next(value);
}
const result = this._conditionalFormattingService.composeStyle(context.unitId, context.subUnitId, context.row, context.col);
if (result?.style && value?.p) {
const keys = Object.keys(result?.style);
if (keys.length > 0) {
const v = BuildTextUtils.transform.getPlainText(value.p.body?.dataStream ?? '');
const s = { ...(typeof value.s === 'string' ? context.workbook.getStyles().get(value.s) : value.s) || {} };
keys.forEach((key) => {
delete s[key as keyof typeof s];
});
const cellData = { ...value, s: { ...s }, v };
delete cellData.p;
return next(cellData);
}
const cfStyle = result?.style ?? {};
const keys = Object.keys(cfStyle);
if (value?.p) {
value.p.body?.textRuns?.forEach((item) => {
if (item.ts) {
keys.forEach((key) => {
delete item.ts?.[key as keyof typeof item.ts];
});
}
});
return next(value);
} else {
const s = { ...(typeof value?.s === 'string' ? context.workbook.getStyles().get(value.s) : value?.s) || {} };
keys.forEach((key) => {
delete s[key as keyof typeof s];
});
const cellData = { ...value, s: { ...s } };
return next(cellData);
}
return next(value);
},
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ export class NumfmtEditorController extends Disposable {
handler: (value, context, next) => {
// clear the effect
this._collectEffectMutation.clean();
const { worksheet, row, col } = context;
const currentNumfmtValue = this._numfmtService.getValue(
context.unitId,
context.subUnitId,
Expand Down Expand Up @@ -204,9 +203,7 @@ export class NumfmtEditorController extends Disposable {
);
}
const v = Number(numfmtInfo.v);
// The format needs to discard the current style settings
const originStyle = worksheet.getCellStyleOnly(row, col)?.s;
return { ...value, v, p: null, s: originStyle, t: CellValueType.NUMBER };
return next({ ...value, p: undefined, v, t: CellValueType.NUMBER });
} else if (['date', 'time', 'datetime', 'percent'].includes(currentNumfmtType) || !isNumeric(content)) {
clean();
}
Expand Down