Skip to content

Commit

Permalink
fix(conditional-formatting): the style that involves conditional form…
Browse files Browse the repository at this point in the history
…atting does not fall

close dream-num/univer-pro#2495
  • Loading branch information
Gggpound committed Nov 30, 2024
1 parent 0f651d6 commit c133344
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
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

0 comments on commit c133344

Please sign in to comment.