Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
fix(sheet): restore code in setStyleCommand (#2225)
siame1f4a3712749
diff --git a/packages/sheets/src/commands/commands/__tests__/set-style.command.spec.ts b/packages/sheets/src/commands/commands/__tests__/set-style.command.spec.tsindex bb1cebe0ef..bb2df4fa20 100644--- a/packages/sheets/src/commands/commands/__tests__/set-style.command.spec.ts+++ b/packages/sheets/src/commands/commands/__tests__/set-style.command.spec.ts@@ -14,7 +14,7 @@* limitations under the License.*/-import type { ITextDecoration, ITextRotation, Univer } from '@univerjs/core';+import type { IColorStyle, ITextDecoration, ITextRotation, Univer } from '@univerjs/core';import {BooleanNumber,FontItalic,@@ -33,6 +33,7 @@ import { afterEach, beforeEach, describe, expect, it } from 'vitest';import { NORMAL_SELECTION_PLUGIN_NAME, SelectionManagerService } from '../../../services/selection-manager.service';import { SetRangeValuesMutation } from '../../mutations/set-range-values.mutation';+import type { ISetStyleCommandParams } from '../set-style.command';import {SetBackgroundColorCommand,SetBoldCommand,@@ -81,6 +82,50 @@ describe("Test commands used for updating cells' styles", () => {afterEach(() => univer.dispose());+ it('set array of style', async () => {+ const range = { startRow: 1, startColumn: 1, endColumn: 3, endRow: 3, rangeType: RANGE_TYPE.NORMAL };++ function getFontColor(row: number, col: number) {+ return get(IUniverInstanceService)+ .getUniverSheetInstance('test')!+ .getSheetBySheetId('sheet1')!+ .getRange(row, col)+ .getFontColor();+ }++ const defaultColor = '#000';+ const color1 = '#aaa';+ const color2 = '#bbb';+ const color3 = '#ccc';+ const commandParams: ISetStyleCommandParams<IColorStyle[][]> = {+ range,+ /** Set style by array */+ style: {+ type: 'cl',+ value: [+ [{ rgb: color1 }, { rgb: color1 }, { rgb: color1 }],+ [{ rgb: color2 }, { rgb: color2 }, { rgb: color2 }],+ [{ rgb: color3 }, { rgb: color3 }, { rgb: color3 }],+ ],+ },+ };+ expect(await commandService.executeCommand(SetStyleCommand.id, commandParams)).toBeTruthy();+ expect(getFontColor(0, 0)).toBe(defaultColor);+ expect(getFontColor(1, 1)).toBe(color1);+ expect(getFontColor(2, 1)).toBe(color2);+ expect(getFontColor(3, 1)).toBe(color3);+ // undo+ expect(await commandService.executeCommand(UndoCommand.id)).toBeTruthy();+ expect(getFontColor(1, 1)).toBe(defaultColor);+ expect(getFontColor(2, 1)).toBe(defaultColor);+ expect(getFontColor(3, 1)).toBe(defaultColor);+ // redo+ expect(await commandService.executeCommand(RedoCommand.id)).toBeTruthy();+ expect(getFontColor(1, 1)).toBe(color1);+ expect(getFontColor(2, 1)).toBe(color2);+ expect(getFontColor(3, 1)).toBe(color3);+ });+describe('bold', () => {describe('correct situations', () => {it('will toggle bold style when there is a selected range', async () => {diff --git a/packages/sheets/src/commands/commands/set-style.command.ts b/packages/sheets/src/commands/commands/set-style.command.tsindex a3615b177a..83aeeaa4ad 100644--- a/packages/sheets/src/commands/commands/set-style.command.ts+++ b/packages/sheets/src/commands/commands/set-style.command.ts@@ -93,9 +93,9 @@ export const SetStyleCommand: ICommand<ISetStyleCommandParams<unknown>> = {if (Tools.isArray(style.value)) {for (let i = 0; i < ranges.length; i++) {iterator.forOperableEach(ranges[i], (r, c, range) => {- cellValue.setValue(r + range.startRow, c + range.startColumn, {+ cellValue.setValue(r, c, {s: {- [style.type]: (style.value as T[][])[r][c],+ [style.type]: (style.value as T[][])[r - range.startRow][c - range.startColumn],},});});