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(sheets): undo set col width should set to the original value (#3353)
Wenzhao Huc5ebb79c9ddd
diff --git a/packages/sheets-ui/src/controllers/auto-height.controller.ts b/packages/sheets-ui/src/controllers/auto-height.controller.tsindex 78beb99407..7bf98c11ee 100644--- a/packages/sheets-ui/src/controllers/auto-height.controller.ts+++ b/packages/sheets-ui/src/controllers/auto-height.controller.ts@@ -51,14 +51,12 @@ export class AutoHeightController extends Disposable {}getUndoRedoParamsOfAutoHeight(ranges: IRange[]) {- const {- _univerInstanceService: univerInstanceService,- _injector: injector,- } = this;+ const { _univerInstanceService: univerInstanceService } = this;const workbook = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!;+ const worksheet = workbook.getActiveSheet();const unitId = workbook.getUnitId();- const subUnitId = workbook.getActiveSheet()?.getSheetId();+ const subUnitId = worksheet.getSheetId();const sheetSkeletonService = this._renderManagerService.getRenderById(unitId)!.with<SheetSkeletonManagerService>(SheetSkeletonManagerService);if (!subUnitId || !sheetSkeletonService.getCurrent()) {@@ -75,10 +73,7 @@ export class AutoHeightController extends Disposable {unitId,rowsAutoHeightInfo,};- const undoParams: ISetWorksheetRowAutoHeightMutationParams = SetWorksheetRowAutoHeightMutationFactory(- injector,- redoParams- );+ const undoParams: ISetWorksheetRowAutoHeightMutationParams = SetWorksheetRowAutoHeightMutationFactory(redoParams, worksheet);return {undos: [{diff --git a/packages/sheets-ui/src/services/auto-fill/auto-fill.service.ts b/packages/sheets-ui/src/services/auto-fill/auto-fill.service.tsindex 6a9da7e491..c977ab405c 100644--- a/packages/sheets-ui/src/services/auto-fill/auto-fill.service.ts+++ b/packages/sheets-ui/src/services/auto-fill/auto-fill.service.ts@@ -378,38 +378,17 @@ export class AutoFillService extends Disposable implements IAutoFillService {}private _getAutoHeightUndoRedos(unitId: string, subUnitId: string, ranges: IRange[]) {- const sheetSkeletonService = this._renderManagerService.getRenderById(unitId)?.with<SheetSkeletonManagerService>(SheetSkeletonManagerService);+ const sheetSkeletonService = this._renderManagerService.getRenderById(unitId)?.with(SheetSkeletonManagerService);const skeleton = sheetSkeletonService?.getCurrent()?.skeleton;- if (!skeleton) {- return {- redos: [],- undos: [],- };- }- const rowsAutoHeightInfo = skeleton.calculateAutoHeightInRange(ranges);+ if (!skeleton) return { redos: [], undos: [] };- const redoParams: ISetWorksheetRowAutoHeightMutationParams = {- subUnitId,- unitId,- rowsAutoHeightInfo,- };- const undoParams: ISetWorksheetRowAutoHeightMutationParams = SetWorksheetRowAutoHeightMutationFactory(- this._injector,- redoParams- );+ const rowsAutoHeightInfo = skeleton.calculateAutoHeightInRange(ranges);+ const redoParams: ISetWorksheetRowAutoHeightMutationParams = { subUnitId, unitId, rowsAutoHeightInfo };+ const worksheet = skeleton.worksheet;+ const undoParams = SetWorksheetRowAutoHeightMutationFactory(redoParams, worksheet);return {- undos: [- {- id: SetWorksheetRowAutoHeightMutation.id,- params: undoParams,- },- ],- redos: [- {- id: SetWorksheetRowAutoHeightMutation.id,- params: redoParams,- },- ],+ undos: [{ id: SetWorksheetRowAutoHeightMutation.id, params: undoParams }],+ redos: [{ id: SetWorksheetRowAutoHeightMutation.id, params: redoParams }],};}}diff --git a/packages/sheets/src/commands/commands/__tests__/create-command-test-bed.ts b/packages/sheets/src/commands/commands/__tests__/create-command-test-bed.tsindex d831c0b725..18cb9e930a 100644--- a/packages/sheets/src/commands/commands/__tests__/create-command-test-bed.ts+++ b/packages/sheets/src/commands/commands/__tests__/create-command-test-bed.ts@@ -110,7 +110,7 @@ export function createCommandTestBed(workbookData?: IWorkbookData, dependencies?}univer.registerPlugin(TestPlugin);- const sheet = univer.createUniverSheet(Tools.deepClone(workbookData || TEST_WORKBOOK_DATA_DEMO));+ const sheet = univer.createUnit<IWorkbookData, Workbook>(UniverInstanceType.UNIVER_SHEET, Tools.deepClone(workbookData || TEST_WORKBOOK_DATA_DEMO));const univerInstanceService = injector.get(IUniverInstanceService);univerInstanceService.focusUnit('test');diff --git a/packages/sheets/src/commands/commands/__tests__/set-col-width.command.spec.ts b/packages/sheets/src/commands/commands/__tests__/set-col-width.command.spec.tsindex 0a03370e56..ce781e9bcb 100644--- a/packages/sheets/src/commands/commands/__tests__/set-col-width.command.spec.ts+++ b/packages/sheets/src/commands/commands/__tests__/set-col-width.command.spec.ts@@ -27,35 +27,28 @@ import { createCommandTestBed } from './create-command-test-bed';describe('Test set col width commands', () => {let univer: Univer;let get: Injector['get'];+let commandService: ICommandService;+ let selectionsService: SheetsSelectionsService;function getColumnWidth(col: number): number {const worksheet = get(IUniverInstanceService).getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!.getActiveSheet()!;return worksheet.getColumnWidth(col);}- beforeEach(() => {- const testBed = createCommandTestBed();- univer = testBed.univer;- get = testBed.get;-- commandService = get(ICommandService);- commandService.registerCommand(DeltaColumnWidthCommand);- commandService.registerCommand(SetColWidthCommand);- commandService.registerCommand(SetWorksheetColWidthMutation);-+ function setSelection(start: number, end: number): void {const worksheet = get(IUniverInstanceService).getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!.getActiveSheet()!;const maxRow = worksheet.getMaxRows() - 1;- const selectionManagerService = get(SheetsSelectionsService);- selectionManagerService.addSelections([++ selectionsService.setSelections([{- range: { startRow: 0, startColumn: 1, endColumn: 2, endRow: maxRow, rangeType: RANGE_TYPE.COLUMN },+ range: { startRow: 0, startColumn: start, endColumn: end, endRow: maxRow, rangeType: RANGE_TYPE.COLUMN },primary: {startRow: 0,- startColumn: 1,- endColumn: 1,+ startColumn: start,+ endColumn: start,endRow: 0,- actualColumn: 1,+ actualColumn: start,actualRow: 1,isMerged: false,isMergedMainCell: false,@@ -63,13 +56,38 @@ describe('Test set col width commands', () => {style: null,},]);- selectionManagerService.addSelections([+ }++ function addSelection(start: number, end: number): void {+ const worksheet = get(IUniverInstanceService).getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!.getActiveSheet()!;+ const maxRow = worksheet.getMaxRows() - 1;++ selectionsService.addSelections([{- range: { startRow: 0, startColumn: 5, endColumn: 5, endRow: maxRow, rangeType: RANGE_TYPE.COLUMN },+ range: { startRow: 0, startColumn: start, endColumn: end, endRow: maxRow, rangeType: RANGE_TYPE.COLUMN },primary: null,style: null,},]);+ }++ beforeEach(() => {+ const testBed = createCommandTestBed();+ univer = testBed.univer;+ get = testBed.get;++ commandService = get(ICommandService);+ commandService.registerCommand(DeltaColumnWidthCommand);+ commandService.registerCommand(SetColWidthCommand);+ commandService.registerCommand(SetWorksheetColWidthMutation);++ const worksheet = get(IUniverInstanceService).getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!.getActiveSheet()!;+ const maxRow = worksheet.getMaxRows() - 1;+ selectionsService = get(SheetsSelectionsService);++ // Select col 1 and 5+ setSelection(1, 2);+ addSelection(5, 5);});afterEach(() => univer.dispose());@@ -97,6 +115,29 @@ describe('Test set col width commands', () => {expect(getColumnWidth(5)).toBe(65);});+ // Fix https://github.com/dream-num/univer-pro/issues/2302.+ it('Should undo to original col widths', async () => {+ expect(getColumnWidth(1)).toBe(88);++ setSelection(1, 1);+ await commandService.executeCommand<IDeltaColumnWidthCommandParams>(DeltaColumnWidthCommand.id, { deltaX: -23, anchorCol: 1 });+ expect(getColumnWidth(1)).toBe(65);+ expect(getColumnWidth(2)).toBe(88);+ setSelection(2, 2);+ await commandService.executeCommand<IDeltaColumnWidthCommandParams>(DeltaColumnWidthCommand.id, { deltaX: 22, anchorCol: 2 });+ expect(getColumnWidth(1)).toBe(65);+ expect(getColumnWidth(2)).toBe(110);++ setSelection(1, 2);+ await commandService.executeCommand<IDeltaColumnWidthCommandParams>(DeltaColumnWidthCommand.id, { deltaX: 50, anchorCol: 2 });+ expect(getColumnWidth(1)).toBe(160);+ expect(getColumnWidth(2)).toBe(160);++ await commandService.executeCommand(UndoCommand.id);+ expect(getColumnWidth(1)).toBe(65);+ expect(getColumnWidth(2)).toBe(110);+ });+it('Should expand only the anchor col in other situations', () => {expect(getColumnWidth(1)).toBe(88);expect(getColumnWidth(7)).toBe(88);diff --git a/packages/sheets/src/commands/commands/set-worksheet-col-width.command.ts b/packages/sheets/src/commands/commands/set-worksheet-col-width.command.tsindex 51e69f909b..b254cb83c3 100644--- a/packages/sheets/src/commands/commands/set-worksheet-col-width.command.ts+++ b/packages/sheets/src/commands/commands/set-worksheet-col-width.command.ts@@ -46,7 +46,6 @@ export const DeltaColumnWidthCommand: ICommand<IDeltaColumnWidthCommandParams> =handler: async (accessor: IAccessor, params: IDeltaColumnWidthCommandParams) => {const selectionManagerService = accessor.get(SheetsSelectionsService);const selections = selectionManagerService.getCurrentSelections();- const sheetInterceptorService = accessor.get(SheetInterceptorService);if (!selections?.length) {return false;@@ -120,8 +119,8 @@ export const DeltaColumnWidthCommand: ICommand<IDeltaColumnWidthCommandParams> =});const undoMutationParams: ISetWorksheetColWidthMutationParams = SetWorksheetColWidthMutationFactory(- accessor,- redoMutationParams+ redoMutationParams,+ worksheet);const setColWidthResult = commandService.syncExecuteCommand(@@ -168,21 +167,16 @@ export const SetColWidthCommand: ICommand = {const target = getSheetCommandTarget(accessor.get(IUniverInstanceService), params);if (!target) return false;- const { subUnitId, unitId } = target;+ const { subUnitId, unitId, worksheet } = target;const redoMutationParams: ISetWorksheetColWidthMutationParams = {subUnitId,unitId,ranges: selections,colWidth: params.value,};- const undoMutationParams: ISetWorksheetColWidthMutationParams = SetWorksheetColWidthMutationFactory(- accessor,- redoMutationParams- );- const setColWidthResult = commandService.syncExecuteCommand(- SetWorksheetColWidthMutation.id,- redoMutationParams- );++ const undoMutationParams = SetWorksheetColWidthMutationFactory(redoMutationParams, worksheet);+ const setColWidthResult = commandService.syncExecuteCommand(SetWorksheetColWidthMutation.id, redoMutationParams);const { undos, redos } = accessor.get(SheetInterceptorService).onCommandExecute({id: SetColWidthCommand.id,diff --git a/packages/sheets/src/commands/commands/set-worksheet-row-height.command.ts b/packages/sheets/src/commands/commands/set-worksheet-row-height.command.tsindex 2b3fff832a..cbfafae0df 100644--- a/packages/sheets/src/commands/commands/set-worksheet-row-height.command.ts+++ b/packages/sheets/src/commands/commands/set-worksheet-row-height.command.ts@@ -117,10 +117,7 @@ export const DeltaRowHeightCommand: ICommand = {};}- const undoMutationParams: ISetWorksheetRowHeightMutationParams = SetWorksheetRowHeightMutationFactory(- accessor,- redoMutationParams- );+ const undoMutationParams: ISetWorksheetRowHeightMutationParams = SetWorksheetRowHeightMutationFactory(redoMutationParams, worksheet);const redoSetIsAutoHeightParams: ISetWorksheetRowIsAutoHeightMutationParams = {unitId,@@ -130,7 +127,7 @@ export const DeltaRowHeightCommand: ICommand = {};const undoSetIsAutoHeightParams: ISetWorksheetRowIsAutoHeightMutationParams =- SetWorksheetRowIsAutoHeightMutationFactory(accessor, redoSetIsAutoHeightParams);+ SetWorksheetRowIsAutoHeightMutationFactory(redoSetIsAutoHeightParams, worksheet);const commandService = accessor.get(ICommandService);const undoRedoService = accessor.get(IUndoRedoService);@@ -215,7 +212,7 @@ export const SetRowHeightCommand: ICommand = {const target = getSheetCommandTarget(univerInstanceService, params);if (!target) return false;- const { unitId, subUnitId } = target;+ const { unitId, subUnitId, worksheet } = target;const redoMutationParams: ISetWorksheetRowHeightMutationParams = {subUnitId,@@ -224,10 +221,7 @@ export const SetRowHeightCommand: ICommand = {rowHeight: params.value,};- const undoMutationParams: ISetWorksheetRowHeightMutationParams = SetWorksheetRowHeightMutationFactory(- accessor,- redoMutationParams- );+ const undoMutationParams: ISetWorksheetRowHeightMutationParams = SetWorksheetRowHeightMutationFactory(redoMutationParams, worksheet);const redoSetIsAutoHeightParams: ISetWorksheetRowIsAutoHeightMutationParams = {unitId,@@ -237,7 +231,7 @@ export const SetRowHeightCommand: ICommand = {};const undoSetIsAutoHeightParams: ISetWorksheetRowIsAutoHeightMutationParams =- SetWorksheetRowIsAutoHeightMutationFactory(accessor, redoSetIsAutoHeightParams);+ SetWorksheetRowIsAutoHeightMutationFactory(redoSetIsAutoHeightParams, worksheet);const result = sequenceExecute([{@@ -310,7 +304,7 @@ export const SetWorksheetRowIsAutoHeightCommand: ICommand = {const target = getSheetCommandTarget(univerInstanceService, params);if (!target) return false;- const { unitId, subUnitId } = target;+ const { unitId, subUnitId, worksheet } = target;const ranges = params?.ranges?.length ? params.ranges : selectionManagerService.getCurrentSelections()?.map((s) => s.range);if (!ranges?.length) {@@ -325,7 +319,7 @@ export const SetWorksheetRowIsAutoHeightCommand: ICommand = {};const undoMutationParams: ISetWorksheetRowIsAutoHeightMutationParams =- SetWorksheetRowIsAutoHeightMutationFactory(accessor, redoMutationParams);+ SetWorksheetRowIsAutoHeightMutationFactory(redoMutationParams, worksheet);const setIsAutoHeightResult = commandService.syncExecuteCommand(SetWorksheetRowIsAutoHeightMutation.id,diff --git a/packages/sheets/src/commands/mutations/__tests__/create-command-test-bed.ts b/packages/sheets/src/commands/mutations/__tests__/create-command-test-bed.tsindex e02391c6da..8670e4b290 100644--- a/packages/sheets/src/commands/mutations/__tests__/create-command-test-bed.ts+++ b/packages/sheets/src/commands/mutations/__tests__/create-command-test-bed.ts@@ -125,7 +125,7 @@ export function createCommandTestBed(workbookData?: IWorkbookData, dependencies?}univer.registerPlugin(TestPlugin);- const sheet = univer.createUniverSheet(workbookData || TEST_WORKBOOK_DATA_DEMO());+ const sheet = univer.createUnit<IWorkbookData, Workbook>(UniverInstanceType.UNIVER_SHEET, workbookData || TEST_WORKBOOK_DATA_DEMO());const univerInstanceService = injector.get(IUniverInstanceService);univerInstanceService.focusUnit('test');diff --git a/packages/sheets/src/commands/mutations/set-worksheet-col-width.mutation.ts b/packages/sheets/src/commands/mutations/set-worksheet-col-width.mutation.tsindex ae21393e2c..12408ea46b 100644--- a/packages/sheets/src/commands/mutations/set-worksheet-col-width.mutation.ts+++ b/packages/sheets/src/commands/mutations/set-worksheet-col-width.mutation.ts@@ -14,9 +14,11 @@* limitations under the License.*/-import type { IAccessor, IMutation, IObjectArrayPrimitiveType, IRange, Nullable } from '@univerjs/core';+import type { IMutation, IObjectArrayPrimitiveType, IRange, Nullable, Worksheet } from '@univerjs/core';import { CommandType, IUniverInstanceService } from '@univerjs/core';+import { getSheetCommandTarget } from '../commands/utils/target-util';+export interface ISetWorksheetColWidthMutationParams {unitId: string;subUnitId: string;@@ -24,24 +26,20 @@ export interface ISetWorksheetColWidthMutationParams {colWidth: number | IObjectArrayPrimitiveType<Nullable<number>>;}+/**+ * This factory is for generating undo mutations for command {@link DeltaColumnWidthCommand}.+ *+ * Note that this mutation may return multi mutations params if the column width is different+ * for each column in the range.+ */export const SetWorksheetColWidthMutationFactory = (- accessor: IAccessor,- params: ISetWorksheetColWidthMutationParams+ params: ISetWorksheetColWidthMutationParams,+ worksheet: Worksheet): ISetWorksheetColWidthMutationParams => {- const univerInstanceService = accessor.get(IUniverInstanceService);- const universheet = univerInstanceService.getUniverSheetInstance(params.unitId);-- if (universheet == null) {- throw new Error('universheet is null error!');- }-- const worksheet = universheet.getSheetBySheetId(params.subUnitId);- if (worksheet == null) {- throw new Error('universheet is null error!');- }+ const { unitId, subUnitId, ranges } = params;const colWidth: IObjectArrayPrimitiveType<Nullable<number>> = {};const manager = worksheet.getColumnManager();- const ranges = params.ranges;+for (let i = 0; i < ranges.length; i++) {const range = ranges[i];for (let j = range.startColumn; j < range.endColumn + 1; j++) {@@ -51,9 +49,9 @@ export const SetWorksheetColWidthMutationFactory = (}return {- unitId: params.unitId,- subUnitId: params.subUnitId,- ranges: params.ranges,+ unitId,+ subUnitId,+ ranges,colWidth,};};@@ -63,17 +61,10 @@ export const SetWorksheetColWidthMutation: IMutation<ISetWorksheetColWidthMutatitype: CommandType.MUTATION,handler: (accessor, params) => {const univerInstanceService = accessor.get(IUniverInstanceService);- const universheet = univerInstanceService.getUniverSheetInstance(params.unitId);-- if (universheet == null) {- throw new Error('universheet is null error!');- }-- const worksheet = universheet.getSheetBySheetId(params.subUnitId);- if (!worksheet) {- return false;- }+ const target = getSheetCommandTarget(univerInstanceService, params);+ if (!target) return false;+ const { worksheet } = target;const defaultColumnWidth = worksheet.getConfig().defaultColumnWidth;const manager = worksheet.getColumnManager();const ranges = params.ranges;@@ -85,7 +76,7 @@ export const SetWorksheetColWidthMutation: IMutation<ISetWorksheetColWidthMutatiif (typeof params.colWidth === 'number') {column.w = params.colWidth;} else {- column.w = params.colWidth[j - range.startColumn] ?? defaultColumnWidth;+ column.w = params.colWidth[j] ?? defaultColumnWidth;}}}diff --git a/packages/sheets/src/commands/mutations/set-worksheet-row-height.mutation.ts b/packages/sheets/src/commands/mutations/set-worksheet-row-height.mutation.tsindex cfeadefc09..1020bbfc31 100644--- a/packages/sheets/src/commands/mutations/set-worksheet-row-height.mutation.ts+++ b/packages/sheets/src/commands/mutations/set-worksheet-row-height.mutation.ts@@ -14,8 +14,9 @@* limitations under the License.*/-import type { BooleanNumber, IAccessor, IMutation, IObjectArrayPrimitiveType, IRange, IRowAutoHeightInfo, Nullable, Workbook } from '@univerjs/core';+import type { BooleanNumber, IMutation, IObjectArrayPrimitiveType, IRange, IRowAutoHeightInfo, Nullable, Worksheet } from '@univerjs/core';import { CommandType, IUniverInstanceService } from '@univerjs/core';+import { getSheetCommandTarget } from '../commands/utils/target-util';const MAXIMUM_ROW_HEIGHT = 2000;@@ -40,17 +41,10 @@ export interface ISetWorksheetRowAutoHeightMutationParams {}export const SetWorksheetRowHeightMutationFactory = (- accessor: IAccessor,- params: ISetWorksheetRowHeightMutationParams+ params: ISetWorksheetRowHeightMutationParams,+ worksheet: Worksheet): ISetWorksheetRowHeightMutationParams => {const { unitId, subUnitId, ranges } = params;- const univerInstanceService = accessor.get(IUniverInstanceService);- const workbook = univerInstanceService.getUniverSheetInstance(unitId);- const worksheet = workbook?.getSheetBySheetId(subUnitId);-- if (worksheet == null) {- throw new Error('worksheet is null error!');- }const rowHeight: IObjectArrayPrimitiveType<Nullable<number>> = {};const manager = worksheet.getRowManager();@@ -71,15 +65,11 @@ export const SetWorksheetRowHeightMutationFactory = (};export const SetWorksheetRowIsAutoHeightMutationFactory = (- accessor: IAccessor,- params: ISetWorksheetRowIsAutoHeightMutationParams+ params: ISetWorksheetRowIsAutoHeightMutationParams,+ worksheet: Worksheet): ISetWorksheetRowIsAutoHeightMutationParams => {const { unitId, subUnitId, ranges } = params;- const univerInstanceService = accessor.get(IUniverInstanceService);- const workbook = univerInstanceService.getUniverSheetInstance(unitId)!;- const worksheet = workbook.getSheetBySheetId(subUnitId)!;-const autoHeightHash: IObjectArrayPrimitiveType<Nullable<BooleanNumber>> = {};const manager = worksheet.getRowManager();@@ -100,22 +90,10 @@ export const SetWorksheetRowIsAutoHeightMutationFactory = (};export const SetWorksheetRowAutoHeightMutationFactory = (- accessor: IAccessor,- params: ISetWorksheetRowAutoHeightMutationParams+ params: ISetWorksheetRowAutoHeightMutationParams,+ worksheet: Worksheet): ISetWorksheetRowAutoHeightMutationParams => {const { unitId, subUnitId, rowsAutoHeightInfo } = params;- const univerInstanceService = accessor.get(IUniverInstanceService);- const workbook = univerInstanceService.getUniverSheetInstance(unitId);- const worksheet = workbook?.getSheetBySheetId(subUnitId);-- if (!worksheet) {- return {- unitId,- subUnitId,- rowsAutoHeightInfo: [],- };- }-const results: IRowAutoHeightInfo[] = [];const manager = worksheet.getRowManager();@@ -123,10 +101,7 @@ export const SetWorksheetRowAutoHeightMutationFactory = (const { row } = rowInfo;const { ah } = manager.getRowOrCreate(row);- results.push({- row,- autoHeight: ah,- });+ results.push({ row, autoHeight: ah });}return {@@ -140,15 +115,12 @@ export const SetWorksheetRowHeightMutation: IMutation<ISetWorksheetRowHeightMutaid: 'sheet.mutation.set-worksheet-row-height',type: CommandType.MUTATION,handler: (accessor, params) => {- const { unitId, subUnitId, ranges, rowHeight } = params;+ const { ranges, rowHeight } = params;const univerInstanceService = accessor.get(IUniverInstanceService);- const workbook = univerInstanceService.getUniverSheetInstance(unitId);-- const worksheet = workbook?.getSheetBySheetId(subUnitId);- if (!worksheet) {- return false;- }+ const target = getSheetCommandTarget(univerInstanceService, params);+ if (!target) return false;+ const { worksheet } = target;const defaultRowHeight = worksheet.getConfig().defaultRowHeight;const manager = worksheet.getRowManager();@@ -174,18 +146,12 @@ export const SetWorksheetRowIsAutoHeightMutation: IMutation<ISetWorksheetRowIsAuid: 'sheet.mutation.set-worksheet-row-is-auto-height',type: CommandType.MUTATION,handler: (accessor, params) => {- const { unitId, subUnitId, ranges, autoHeightInfo } = params;+ const { ranges, autoHeightInfo } = params;const univerInstanceService = accessor.get(IUniverInstanceService);- const workbook = univerInstanceService.getUniverSheetInstance(unitId);-- const worksheet = workbook?.getSheetBySheetId(subUnitId);- if (!worksheet) {- return false;- }-- const defaultRowIsAutoHeight = undefined;- const manager = worksheet.getRowManager();+ const target = getSheetCommandTarget(univerInstanceService, params);+ if (!target) return false;+ const manager = target.worksheet.getRowManager();for (const { startRow, endRow } of ranges) {for (let rowIndex = startRow; rowIndex <= endRow; rowIndex++) {const row = manager.getRowOrCreate(rowIndex);@@ -193,7 +159,7 @@ export const SetWorksheetRowIsAutoHeightMutation: IMutation<ISetWorksheetRowIsAuif (typeof autoHeightInfo === 'number') {row.ia = autoHeightInfo;} else {- row.ia = autoHeightInfo[rowIndex] ?? defaultRowIsAutoHeight; // Start from startRow, same as SetWorksheetRowHeightMutation+ row.ia = autoHeightInfo[rowIndex] ?? undefined;}}}@@ -206,16 +172,12 @@ export const SetWorksheetRowAutoHeightMutation: IMutation<ISetWorksheetRowAutoHeid: 'sheet.mutation.set-worksheet-row-auto-height',type: CommandType.MUTATION,handler: (accessor, params) => {- const { unitId, subUnitId, rowsAutoHeightInfo } = params;+ const { rowsAutoHeightInfo } = params;const univerInstanceService = accessor.get(IUniverInstanceService);- const workbook = univerInstanceService.getUnit<Workbook>(unitId);- const worksheet = workbook?.getSheetBySheetId(subUnitId);-- if (!worksheet || !workbook) {- return false;- }+ const target = getSheetCommandTarget(univerInstanceService, params);+ if (!target) return false;- const rowManager = worksheet.getRowManager();+ const rowManager = target.worksheet.getRowManager();for (const { row, autoHeight } of rowsAutoHeightInfo) {const curRow = rowManager.getRowOrCreate(row);diff --git a/packages/sheets/src/controllers/__tests__/util.ts b/packages/sheets/src/controllers/__tests__/util.tsindex d2970f22cf..0fff075df6 100644--- a/packages/sheets/src/controllers/__tests__/util.ts+++ b/packages/sheets/src/controllers/__tests__/util.ts@@ -14,7 +14,7 @@* limitations under the License.*/-import type { Dependency, IWorkbookData } from '@univerjs/core';+import type { Dependency, IWorkbookData, Workbook } from '@univerjs/core';import { ILogService, Inject, Injector, IUniverInstanceService, LocaleType, LogLevel, Plugin, Univer, UniverInstanceType } from '@univerjs/core';const TEST_WORKBOOK_DATA_DEMO: IWorkbookData = {@@ -66,7 +66,7 @@ export function createTestBase(workbookData?: IWorkbookData, dependencies?: Depe}univer.registerPlugin(TestPlugin);- const sheet = univer.createUniverSheet(workbookData || TEST_WORKBOOK_DATA_DEMO);+ const sheet = univer.createUnit<IWorkbookData, Workbook>(UniverInstanceType.UNIVER_SHEET, workbookData || TEST_WORKBOOK_DATA_DEMO);const univerInstanceService = get(IUniverInstanceService);univerInstanceService.focusUnit('test');diff --git a/packages/sheets/src/services/__tests__/util.ts b/packages/sheets/src/services/__tests__/util.tsindex 547e71f736..ea539bda92 100644--- a/packages/sheets/src/services/__tests__/util.ts+++ b/packages/sheets/src/services/__tests__/util.ts@@ -14,7 +14,7 @@* limitations under the License.*/-import type { Dependency, IWorkbookData } from '@univerjs/core';+import type { Dependency, IWorkbookData, Workbook } from '@univerjs/core';import { CellValueType, ILogService, Inject, Injector, IUniverInstanceService, LocaleType, LogLevel, Plugin, Univer, UniverInstanceType } from '@univerjs/core';import { DEFAULT_TEXT_FORMAT } from '@univerjs/engine-numfmt';@@ -104,7 +104,7 @@ export function createTestBase(workbookData?: IWorkbookData, dependencies?: Depe}univer.registerPlugin(TestPlugin);- const sheet = univer.createUniverSheet(workbookData || TEST_WORKBOOK_DATA_DEMO);+ const sheet = univer.createUnit<IWorkbookData, Workbook>(UniverInstanceType.UNIVER_SHEET, workbookData || TEST_WORKBOOK_DATA_DEMO);const univerInstanceService = get(IUniverInstanceService);univerInstanceService.focusUnit('test');diff --git a/packages/sheets/src/services/ref-range/__tests__/__testing__.ts b/packages/sheets/src/services/ref-range/__tests__/__testing__.tsindex 334ba0f690..f0a3c43896 100644--- a/packages/sheets/src/services/ref-range/__tests__/__testing__.ts+++ b/packages/sheets/src/services/ref-range/__tests__/__testing__.ts@@ -14,7 +14,7 @@* limitations under the License.*/-import type { Dependency, IWorkbookData } from '@univerjs/core';+import type { Dependency, IWorkbookData, Workbook } from '@univerjs/core';import { ILogService, Inject, Injector, IUniverInstanceService, LocaleType, LogLevel, Plugin, Univer, UniverInstanceType } from '@univerjs/core';export const TEST_WORKBOOK_DATA_DEMO: IWorkbookData = {@@ -80,7 +80,7 @@ export function createTestBase(workbookData?: IWorkbookData, dependencies?: Depe}univer.registerPlugin(TestPlugin);- const sheet = univer.createUniverSheet(workbookData || TEST_WORKBOOK_DATA_DEMO);+ const sheet = univer.createUnit<IWorkbookData, Workbook>(UniverInstanceType.UNIVER_SHEET, workbookData || TEST_WORKBOOK_DATA_DEMO);const univerInstanceService = get(IUniverInstanceService);univerInstanceService.focusUnit('test');diff --git a/packages/sheets/src/services/ref-range/__tests__/ref-range.service.spec.ts b/packages/sheets/src/services/ref-range/__tests__/ref-range.service.spec.tsindex 43a210180a..48c66546f9 100644--- a/packages/sheets/src/services/ref-range/__tests__/ref-range.service.spec.ts+++ b/packages/sheets/src/services/ref-range/__tests__/ref-range.service.spec.ts@@ -15,7 +15,7 @@*/import { afterEach, beforeEach, describe, expect, it } from 'vitest';-import type { Dependency, ICommand, IRange, IWorkbookData, Nullable } from '@univerjs/core';+import type { Dependency, ICommand, IRange, IWorkbookData, Nullable, Workbook } from '@univerjs/core';import { ICommandService, ILogService, Inject, Injector, IUniverInstanceService, LocaleType, LogLevel, Plugin, Univer, UniverInstanceType } from '@univerjs/core';import { RefRangeService } from '../ref-range.service';@@ -83,7 +83,7 @@ export function createRefRangeTestBed() {] as ICommand[]).forEach((command) => commandService.registerCommand(command));univer.registerPlugin(TestPlugin);- const sheet = univer.createUniverSheet(TEST_WORKBOOK_DATA);+ const sheet = univer.createUnit<IWorkbookData, Workbook>(UniverInstanceType.UNIVER_SHEET, TEST_WORKBOOK_DATA);const univerInstanceService = get(IUniverInstanceService);univerInstanceService.focusUnit('test');diff --git a/packages/sheets/src/services/sheet-interceptor/__tests__/create-core-test-bed.ts b/packages/sheets/src/services/sheet-interceptor/__tests__/create-core-test-bed.tsindex 893097ddb3..03ba4ca017 100644--- a/packages/sheets/src/services/sheet-interceptor/__tests__/create-core-test-bed.ts+++ b/packages/sheets/src/services/sheet-interceptor/__tests__/create-core-test-bed.ts@@ -14,7 +14,7 @@* limitations under the License.*/-import type { Dependency, IWorkbookData } from '@univerjs/core';+import type { Dependency, IWorkbookData, Workbook } from '@univerjs/core';import { ILogService, Inject, Injector, IUniverInstanceService, LocaleType, LogLevel, Plugin, Univer, UniverInstanceType } from '@univerjs/core';import { SheetInterceptorService } from '../sheet-interceptor.service';@@ -66,7 +66,7 @@ export function createSheetTestBed(workbookData?: IWorkbookData, dependencies?:}univer.registerPlugin(TestPlugin);- const sheet = univer.createUniverSheet(workbookData || TEST_WORKBOOK_DATA);+ const sheet = univer.createUnit<IWorkbookData, Workbook>(UniverInstanceType.UNIVER_SHEET, workbookData || TEST_WORKBOOK_DATA);const univerInstanceService = get(IUniverInstanceService);univerInstanceService.focusUnit('test');