From 7c9451d69f0dc46b14025691464a830ae8bfd35d Mon Sep 17 00:00:00 2001 From: gggpound Date: Sat, 30 Nov 2024 17:41:51 +0800 Subject: [PATCH] fix(conditional-formatting): the style that involves conditional formatting does not fall close https://github.com/dream-num/univer-pro/issues/2495 --- .../src/controllers/cf.editor.controller.ts | 35 +++++++++++-------- .../controllers/numfmt.editor.controller.ts | 5 +-- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/packages/sheets-conditional-formatting-ui/src/controllers/cf.editor.controller.ts b/packages/sheets-conditional-formatting-ui/src/controllers/cf.editor.controller.ts index 6c35d32fdaa..4e7593ee009 100644 --- a/packages/sheets-conditional-formatting-ui/src/controllers/cf.editor.controller.ts +++ b/packages/sheets-conditional-formatting-ui/src/controllers/cf.editor.controller.ts @@ -15,7 +15,6 @@ */ import { - BuildTextUtils, Disposable, Inject, toDisposable, @@ -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); }, } ) diff --git a/packages/sheets-numfmt-ui/src/controllers/numfmt.editor.controller.ts b/packages/sheets-numfmt-ui/src/controllers/numfmt.editor.controller.ts index 2edd1e697ac..c7b3d6796f6 100644 --- a/packages/sheets-numfmt-ui/src/controllers/numfmt.editor.controller.ts +++ b/packages/sheets-numfmt-ui/src/controllers/numfmt.editor.controller.ts @@ -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, @@ -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(); }