From 14c722ed190720d480b1a18e7877cf36a2d7fe4d Mon Sep 17 00:00:00 2001 From: hexf00 Date: Tue, 6 Feb 2024 14:31:46 +0800 Subject: [PATCH] refactor(facade): refactor set font style --- .../src/apis/sheet/__tests__/f-range.spec.ts | 2 +- packages/facade/src/apis/sheet/f-range.ts | 20 +++++-------------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/packages/facade/src/apis/sheet/__tests__/f-range.spec.ts b/packages/facade/src/apis/sheet/__tests__/f-range.spec.ts index 3fb2b299caf..010895d6a7f 100644 --- a/packages/facade/src/apis/sheet/__tests__/f-range.spec.ts +++ b/packages/facade/src/apis/sheet/__tests__/f-range.spec.ts @@ -174,7 +174,7 @@ describe('Test FRange', () => { }); it('Range getCellData', () => { - const activeSheet = univerAPI.getActiveWorkbook()?.getActiveSheet(); + const activeSheet = univerAPI.getActiveWorkbook()!.getActiveSheet(); activeSheet?.getRange(0, 0)?.setValue(1); const range = activeSheet?.getRange(0, 0); expect(range?.getCellData()?.v).toBe(1); diff --git a/packages/facade/src/apis/sheet/f-range.ts b/packages/facade/src/apis/sheet/f-range.ts index b03169ee86f..9f3ec933c67 100644 --- a/packages/facade/src/apis/sheet/f-range.ts +++ b/packages/facade/src/apis/sheet/f-range.ts @@ -412,21 +412,11 @@ export class FRange { * @param color The font color in CSS notation (such as '#ffffff' or 'white'); a null value resets the color. */ setFontColor(color: string | null): this { - let style: IStyleTypeValue; - - if (color === null) { - style = { - type: 'cl', - value: null, - }; - } else { - style = { - type: 'cl', - value: { - rgb: color, - }, - }; - } + const value: IColorStyle | null = color === null ? null : { rgb: color }; + const style: IStyleTypeValue = { + type: 'cl', + value, + }; const setStyleParams: ISetStyleCommandParams = { unitId: this._workbook.getUnitId(),