Skip to content

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.

fix(sheets-formula): handle formula reorder in core plugin (#7852)

白熱0db606503437
diff --git a/packages/sheets-formula-ui/src/controllers/__tests__/formula-reorder.controller.spec.ts b/packages/sheets-formula-ui/src/controllers/__tests__/formula-reorder.controller.spec.ts
deleted file mode 100644
index 66e3d68824..0000000000
--- a/packages/sheets-formula-ui/src/controllers/__tests__/formula-reorder.controller.spec.ts
+++ /dev/null
@@ -1,113 +0,0 @@
-/**
- * Copyright 2023-present DreamNum Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import type { IWorkbookData } from '@univerjs/core';
-import { LocaleType } from '@univerjs/core';
-import { ReorderRangeCommand, SetRangeValuesMutation, SheetInterceptorService } from '@univerjs/sheets';
-import { afterEach, beforeEach, describe, expect, it } from 'vitest';
-import { FormulaReorderController } from '../formula-reorder.controller';
-import { createCommandTestBed } from './create-command-test-bed';
-
-const WORKBOOK_DATA: IWorkbookData = {
- id: 'unit',
- appVersion: '3.0.0-alpha',
- locale: LocaleType.EN_US,
- name: 'Test workbook',
- styles: {},
- sheetOrder: ['sheet'],
- sheets: {
- sheet: {
- id: 'sheet',
- name: 'Sheet 1',
- cellData: {
- 0: { 0: { v: 'old-row' } },
- 1: { 0: { f: '=A2', si: 'shared' } },
- },
- },
- },
-};
-
-describe('FormulaReorderController', () => {
- let univer: ReturnType<typeof createCommandTestBed>['univer'];
- let controller: FormulaReorderController;
- let sheetInterceptorService: SheetInterceptorService;
-
- beforeEach(() => {
- const testBed = createCommandTestBed(WORKBOOK_DATA, [[FormulaReorderController]]);
- univer = testBed.univer;
- controller = testBed.get(FormulaReorderController);
- sheetInterceptorService = testBed.get(SheetInterceptorService);
- });
-
- afterEach(() => univer.dispose());
-
- it('creates redo and undo mutations with formula references shifted to the reordered row', () => {
- const result = sheetInterceptorService.onCommandExecute({
- id: ReorderRangeCommand.id,
- params: {
- unitId: 'unit',
- subUnitId: 'sheet',
- range: { startRow: 0, endRow: 0, startColumn: 0, endColumn: 0 },
- order: { 0: 1 },
- },
- });
-
- expect(result.redos).toEqual([{
- id: SetRangeValuesMutation.id,
- params: {
- unitId: 'unit',
- subUnitId: 'sheet',
- cellValue: {
- 0: {
- 0: { f: '=A1', si: null },
- },
- },
- },
- }]);
- expect(result.undos).toEqual([{
- id: SetRangeValuesMutation.id,
- params: {
- unitId: 'unit',
- subUnitId: 'sheet',
- cellValue: {
- 0: {
- 0: { v: 'old-row' },
- },
- },
- },
- }]);
-
- controller.dispose();
- expect(sheetInterceptorService.onCommandExecute({ id: ReorderRangeCommand.id, params: {} })).toEqual({
- preUndos: [],
- undos: [],
- preRedos: [],
- redos: [],
- });
- });
-
- it('returns empty mutations for non-reorder commands, missing worksheets and ranges without formulas', () => {
- expect(sheetInterceptorService.onCommandExecute({ id: 'other-command', params: {} })).toMatchObject({ redos: [], undos: [] });
- expect(sheetInterceptorService.onCommandExecute({
- id: ReorderRangeCommand.id,
- params: { unitId: 'unit', subUnitId: 'missing', range: { startRow: 0, endRow: 0, startColumn: 0, endColumn: 0 }, order: {} },
- })).toMatchObject({ redos: [], undos: [] });
- expect(sheetInterceptorService.onCommandExecute({
- id: ReorderRangeCommand.id,
- params: { unitId: 'unit', subUnitId: 'sheet', range: { startRow: 0, endRow: 0, startColumn: 0, endColumn: 0 }, order: {} },
- })).toMatchObject({ redos: [], undos: [] });
- });
-});
diff --git a/packages/sheets-formula-ui/src/index.ts b/packages/sheets-formula-ui/src/index.ts
index 4b5129bb91..91c214b8a1 100644
--- a/packages/sheets-formula-ui/src/index.ts
+++ b/packages/sheets-formula-ui/src/index.ts
@@ -27,7 +27,6 @@ export { ReferenceAbsoluteOperation } from './commands/operations/reference-abso
export { SearchFunctionOperation } from './commands/operations/search-function.operation';
export { genFormulaRefSelectionStyle } from './common/selection';
export type { IUniverSheetsFormulaUIConfig } from './config/config';
-export { FormulaReorderController } from './controllers/formula-reorder.controller';
export { menuSchema as SheetsFormulaUIMenuSchema } from './menu/schema';
export { UniverSheetsFormulaMobileUIPlugin } from './mobile-plugin';
export { UniverSheetsFormulaUIPlugin } from './plugin';
diff --git a/packages/sheets-formula-ui/src/mobile-plugin.ts b/packages/sheets-formula-ui/src/mobile-plugin.ts
index 99b3422952..dcb3112e29 100644
--- a/packages/sheets-formula-ui/src/mobile-plugin.ts
+++ b/packages/sheets-formula-ui/src/mobile-plugin.ts
@@ -43,7 +43,6 @@ import { FormulaAlertRenderController } from './controllers/formula-alert-render
import { FormulaClipboardController } from './controllers/formula-clipboard.controller';
import { FormulaEditorShowController } from './controllers/formula-editor-show.controller';
import { FormulaRenderManagerController } from './controllers/formula-render.controller';
-import { FormulaReorderController } from './controllers/formula-reorder.controller';
import { ImageFormulaRenderController } from './controllers/image-formula-render.controller';
import { MobileComponentsController } from './controllers/mobile/components.controller';
import { FormulaUIController } from './controllers/ui.controller';
@@ -102,7 +101,6 @@ export class UniverSheetsFormulaMobileUIPlugin extends Plugin {
[FormulaClipboardController],
[FormulaEditorShowController],
[FormulaRenderManagerController],
- [FormulaReorderController],
[ImageFormulaRenderController],
]);
@@ -134,10 +132,6 @@ export class UniverSheetsFormulaMobileUIPlugin extends Plugin {
]);
}
- override onSteady(): void {
- this._injector.get(FormulaReorderController);
- }
-
private _initUIPart(): void {
this.disposeWithMe(this._uiPartsService.registerComponent(
BuiltInUIPart.GLOBAL,
diff --git a/packages/sheets-formula-ui/src/plugin.ts b/packages/sheets-formula-ui/src/plugin.ts
index 7233f2f0c8..f7dded1ce2 100644
--- a/packages/sheets-formula-ui/src/plugin.ts
+++ b/packages/sheets-formula-ui/src/plugin.ts
@@ -44,7 +44,6 @@ import { FormulaAlertRenderController } from './controllers/formula-alert-render
import { FormulaClipboardController } from './controllers/formula-clipboard.controller';
import { FormulaEditorShowController } from './controllers/formula-editor-show.controller';
import { FormulaRenderManagerController } from './controllers/formula-render.controller';
-import { FormulaReorderController } from './controllers/formula-reorder.controller';
import { ImageFormulaRenderController } from './controllers/image-formula-render.controller';
import { FormulaUIController } from './controllers/ui.controller';
import { FormulaMenuController } from './menu/formula-menu.controller';
@@ -100,7 +99,6 @@ export class UniverSheetsFormulaUIPlugin extends Plugin {
[FormulaClipboardController],
[FormulaEditorShowController],
[FormulaRenderManagerController],
- [FormulaReorderController],
[ImageFormulaRenderController],
]);
@@ -132,10 +130,6 @@ export class UniverSheetsFormulaUIPlugin extends Plugin {
]);
}
- override onSteady(): void {
- this._injector.get(FormulaReorderController);
- }
-
private _initUIPart(): void {
this.disposeWithMe(this._uiPartsService.registerComponent(BuiltInUIPart.GLOBAL, () => connectInjector(GlobalRangeSelector, this._injector)));
}
diff --git a/packages/sheets-formula/src/controllers/__tests__/formula-reorder.controller.spec.ts b/packages/sheets-formula/src/controllers/__tests__/formula-reorder.controller.spec.ts
new file mode 100644
index 0000000000..78b547c8cc
--- /dev/null
+++ b/packages/sheets-formula/src/controllers/__tests__/formula-reorder.controller.spec.ts
@@ -0,0 +1,153 @@
+/**
+ * Copyright 2023-present DreamNum Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// @vitest-environment node
+
+import type { ICommandInfo, IWorkbookData } from '@univerjs/core';
+import { CommandType, ICommandService, LocaleType, LogLevel, Tools, Univer } from '@univerjs/core';
+import { FUniver } from '@univerjs/core/facade';
+import { ReorderRangeCommand, ReorderRangeMutation, SetRangeValuesMutation, SheetInterceptorService } from '@univerjs/sheets';
+import { afterEach, describe, expect, it } from 'vitest';
+import { UniverSheetsFormulaPlugin } from '../../plugin';
+import { FormulaReorderController } from '../formula-reorder.controller';
+import '@univerjs/engine-formula/facade';
+import '@univerjs/sheets/facade';
+
+const WORKBOOK_DATA: IWorkbookData = {
+ id: 'unit',
+ appVersion: 'test',
+ locale: LocaleType.EN_US,
+ name: 'Sort formulas',
+ styles: {},
+ sheetOrder: ['sheet'],
+ sheets: {
+ sheet: {
+ id: 'sheet',
+ name: 'Sheet1',
+ rowCount: 10,
+ columnCount: 10,
+ cellData: {
+ 0: { 0: { v: 'b' }, 1: { v: 2 }, 2: { f: '=B1*10' }, 3: { f: '=$B1+B$1+$B$1' } },
+ 1: { 0: { v: 'a' }, 1: { v: 1 }, 2: { f: '=B2*10' }, 3: { f: '=$B2+B$1+$B$1' } },
+ },
+ },
+ },
+};
+
+const REORDER_PARAMS = {
+ unitId: 'unit',
+ subUnitId: 'sheet',
+ range: { startRow: 0, endRow: 1, startColumn: 0, endColumn: 3 },
+ order: { 0: 1, 1: 0 },
+};
+
+describe('FormulaReorderController without a UI plugin', () => {
+ const instances: Univer[] = [];
+
+ async function createTestBed(data: IWorkbookData = WORKBOOK_DATA) {
+ const univer = new Univer({
+ locale: LocaleType.EN_US,
+ locales: { [LocaleType.EN_US]: {} },
+ logLevel: LogLevel.SILENT,
+ });
+ instances.push(univer);
+ univer.registerPlugin(UniverSheetsFormulaPlugin);
+
+ const api = FUniver.newAPI(univer);
+ const workbook = api.createWorkbook(Tools.deepClone(data));
+ const sheet = workbook.getActiveSheet();
+ const injector = univer.__getInjector();
+ await api.getFormula().onCalculationResultApplied();
+
+ return { api, workbook, sheet, injector, commandService: injector.get(ICommandService) };
+ }
+
+ afterEach(() => {
+ instances.forEach((univer) => univer.dispose());
+ instances.length = 0;
+ });
+
+ it.each([false, true])('keeps relative, mixed and absolute references correct through reorder, undo and redo (shared: %s)', async (shared) => {
+ const data = Tools.deepClone(WORKBOOK_DATA);
+ if (shared) {
+ data.sheets.sheet.cellData![0][2] = { f: '=B1*10', si: 'shared' };
+ data.sheets.sheet.cellData![1][2] = { si: 'shared' };
+ }
+ const { api, workbook, sheet, commandService } = await createTestBed(data);
+ const formulas = [['=B1*10', '=$B1+B$1+$B$1'], ['=B2*10', '=$B2+B$1+$B$1']];
+
+ expect(commandService.syncExecuteCommand(ReorderRangeCommand.id, REORDER_PARAMS)).toBe(true);
+ await api.getFormula().onCalculationResultApplied();
+ expect(sheet.getRange('A1:D2').getValues()).toEqual([['a', 1, 10, 3], ['b', 2, 20, 4]]);
+ expect(sheet.getRange('C1:D2').getFormulas()).toEqual(formulas);
+
+ workbook.undo();
+ await api.getFormula().onCalculationResultApplied();
+ expect(sheet.getRange('A1:D2').getValues()).toEqual([['b', 2, 20, 6], ['a', 1, 10, 5]]);
+ expect(sheet.getRange('C1:D2').getFormulas()).toEqual(formulas);
+
+ workbook.redo();
+ await api.getFormula().onCalculationResultApplied();
+ expect(sheet.getRange('A1:D2').getValues()).toEqual([['a', 1, 10, 3], ['b', 2, 20, 4]]);
+ expect(sheet.getRange('C1:D2').getFormulas()).toEqual(formulas);
+ });
+
+ it('skips unrelated commands, missing worksheets and ranges without formulas, and unregisters on disposal', async () => {
+ const { injector } = await createTestBed();
+ const interceptor = injector.get(SheetInterceptorService);
+
+ expect(interceptor.onCommandExecute({ id: 'other-command', params: {} })).toMatchObject({ redos: [], undos: [] });
+ expect(interceptor.onCommandExecute({
+ id: ReorderRangeCommand.id,
+ params: { ...REORDER_PARAMS, subUnitId: 'missing' },
+ })).toMatchObject({ redos: [], undos: [] });
+ expect(interceptor.onCommandExecute({
+ id: ReorderRangeCommand.id,
+ params: { ...REORDER_PARAMS, range: { ...REORDER_PARAMS.range, endColumn: 1 } },
+ })).toMatchObject({ redos: [], undos: [] });
+
+ injector.get(FormulaReorderController).dispose();
+ expect(interceptor.onCommandExecute({ id: ReorderRangeCommand.id, params: REORDER_PARAMS })).toMatchObject({ redos: [], undos: [] });
+ });
+
+ it('preserves corrected formulas when saving a snapshot or replaying recorded mutations', async () => {
+ const { api, workbook, sheet, commandService } = await createTestBed();
+ const original = workbook.save();
+ const mutations: ICommandInfo[] = [];
+ const recording = commandService.onCommandExecuted((command, options) => {
+ if (command.type === CommandType.MUTATION && !options?.onlyLocal) {
+ mutations.push(Tools.deepClone(command));
+ }
+ });
+
+ expect(commandService.syncExecuteCommand(ReorderRangeCommand.id, REORDER_PARAMS)).toBe(true);
+ recording.dispose();
+ await api.getFormula().onCalculationResultApplied();
+ expect(mutations.map((mutation) => mutation.id)).toEqual([ReorderRangeMutation.id, SetRangeValuesMutation.id]);
+
+ const restored = await createTestBed(JSON.parse(JSON.stringify(workbook.save())));
+ expect(restored.sheet.getRange('A1:D2').getValues()).toEqual([['a', 1, 10, 3], ['b', 2, 20, 4]]);
+ expect(restored.sheet.getRange('C1:D2').getFormulas()).toEqual(sheet.getRange('C1:D2').getFormulas());
+
+ const replica = await createTestBed(original);
+ for (const mutation of mutations) {
+ expect(replica.commandService.syncExecuteCommand(mutation.id, mutation.params, { fromChangeset: true })).toBe(true);
+ }
+ await replica.api.getFormula().onCalculationResultApplied();
+ expect(replica.sheet.getRange('A1:D2').getValues()).toEqual([['a', 1, 10, 3], ['b', 2, 20, 4]]);
+ expect(replica.sheet.getRange('C1:D2').getFormulas()).toEqual(sheet.getRange('C1:D2').getFormulas());
+ });
+});
diff --git a/packages/sheets-formula-ui/src/controllers/formula-reorder.controller.ts b/packages/sheets-formula/src/controllers/formula-reorder.controller.ts
similarity index 98%
rename from packages/sheets-formula-ui/src/controllers/formula-reorder.controller.ts
rename to packages/sheets-formula/src/controllers/formula-reorder.controller.ts
index 743163d669..94ed9ff216 100644
--- a/packages/sheets-formula-ui/src/controllers/formula-reorder.controller.ts
+++ b/packages/sheets-formula/src/controllers/formula-reorder.controller.ts
@@ -78,7 +78,7 @@ export class FormulaReorderController extends Disposable {
Range.foreach(range, (row, col) => {
let targetRow = row;
- if (order.hasOwnProperty(row)) {
+ if (Object.prototype.hasOwnProperty.call(order, row)) {
targetRow = order[row];
}
diff --git a/packages/sheets-formula/src/index.ts b/packages/sheets-formula/src/index.ts
index 142b345c33..3ee102d497 100644
--- a/packages/sheets-formula/src/index.ts
+++ b/packages/sheets-formula/src/index.ts
@@ -19,6 +19,7 @@ export type { IInsertFunction, IInsertFunctionCommandParams } from './commands/c
export { CalculationMode, PLUGIN_CONFIG_KEY_BASE } from './config/config';
export type { IUniverSheetsFormulaBaseConfig, IUniverSheetsFormulaRemoteConfig } from './config/config';
export { FormulaAutoFillController } from './controllers/formula-auto-fill.controller';
+export { FormulaReorderController } from './controllers/formula-reorder.controller';
export { ImageFormulaCellInterceptorController } from './controllers/image-formula-cell-interceptor.controller';
export { TriggerCalculationController } from './controllers/trigger-calculation.controller';
export { collectUnitQualifierFormulaPatches, UnitQualifierRenameController } from './controllers/unit-qualifier-rename.controller';
diff --git a/packages/sheets-formula/src/plugin.ts b/packages/sheets-formula/src/plugin.ts
index 819bd4d616..0d76ffdb0a 100644
--- a/packages/sheets-formula/src/plugin.ts
+++ b/packages/sheets-formula/src/plugin.ts
@@ -42,6 +42,7 @@ import { ActiveDirtyController } from './controllers/active-dirty.controller';
import { ArrayFormulaCellInterceptorController } from './controllers/array-formula-cell-interceptor.controller';
import { DefinedNameController } from './controllers/defined-name.controller';
import { FormulaAutoFillController } from './controllers/formula-auto-fill.controller';
+import { FormulaReorderController } from './controllers/formula-reorder.controller';
import { FormulaController } from './controllers/formula.controller';
import { ImageFormulaCellInterceptorController } from './controllers/image-formula-cell-interceptor.controller';
import {
@@ -129,6 +130,7 @@ export class UniverSheetsFormulaPlugin extends Plugin {
[UpdateDefinedNameController],
[SuperTableController],
[FormulaAutoFillController],
+ [FormulaReorderController],
[UnitQualifierRenameController],
];
@@ -157,6 +159,7 @@ export class UniverSheetsFormulaPlugin extends Plugin {
[UpdateFormulaController],
[UpdateDefinedNameController],
[FormulaAutoFillController],
+ [FormulaReorderController],
[UnitQualifierRenameController],
[SheetFormulaCalculationResultApplyController],
]);
diff --git a/packages/sheets-sort-ui/package.json b/packages/sheets-sort-ui/package.json
index 12007d20ac..07b78cf52e 100644
--- a/packages/sheets-sort-ui/package.json
+++ b/packages/sheets-sort-ui/package.json
@@ -85,7 +85,7 @@
},
"devDependencies": {
"@univerjs-infra/shared": "workspace:*",
- "@univerjs/sheets-formula-ui": "workspace:*",
+ "@univerjs/sheets-formula": "workspace:*",
"postcss": "^8.5.28",
"react": "18.3.1",
"rxjs": "^7.8.2",
diff --git a/packages/sheets-sort-ui/src/commands/commands/__tests__/create-command-test-bed.ts b/packages/sheets-sort-ui/src/commands/commands/__tests__/create-command-test-bed.ts
index 5704fe41bc..ac060a05f5 100644
--- a/packages/sheets-sort-ui/src/commands/commands/__tests__/create-command-test-bed.ts
+++ b/packages/sheets-sort-ui/src/commands/commands/__tests__/create-command-test-bed.ts
@@ -18,7 +18,7 @@ import type { Dependency, IWorkbookData, Workbook } from '@univerjs/core';
import { ILogService, Inject, Injector, IUniverInstanceService, LocaleService, LocaleType, LogLevel, Plugin, Tools, Univer, UniverInstanceType } from '@univerjs/core';
import { FormulaCurrentConfigService, FormulaDataModel, FormulaRuntimeService, HyperlinkEngineFormulaService, IFormulaCurrentConfigService, IFormulaRuntimeService, IHyperlinkEngineFormulaService, LexerTreeBuilder } from '@univerjs/engine-formula';
import { SheetInterceptorService, SheetsSelectionsService } from '@univerjs/sheets';
-import { FormulaReorderController } from '@univerjs/sheets-formula-ui';
+import { FormulaReorderController } from '@univerjs/sheets-formula';
import { SheetsSortService } from '@univerjs/sheets-sort';
import { SheetsSortController } from '@univerjs/sheets-sort/controllers/sheets-sort.controller.js';
import zhCN from '../../../locale/zh-CN';
diff --git a/packages/sheets-sort-ui/src/commands/commands/__tests__/formula-reorder.spec.ts b/packages/sheets-sort-ui/src/commands/commands/__tests__/formula-reorder.spec.ts
deleted file mode 100644
index 40df919530..0000000000
--- a/packages/sheets-sort-ui/src/commands/commands/__tests__/formula-reorder.spec.ts
+++ /dev/null
@@ -1,115 +0,0 @@
-/**
- * Copyright 2023-present DreamNum Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import type { ICellData, Injector, Nullable, Univer, Workbook } from '@univerjs/core';
-import { ICommandService, IConfirmService, IUniverInstanceService, RANGE_TYPE, TestConfirmService, UniverInstanceType } from '@univerjs/core';
-import { ReorderRangeCommand, ReorderRangeMutation, SetRangeValuesMutation, SheetsSelectionsService } from '@univerjs/sheets';
-import { afterEach, beforeEach, describe, expect, it } from 'vitest';
-import { SheetsSortUIService } from '../../../services/sheets-sort-ui.service';
-import { createCommandTestBed } from './create-command-test-bed';
-
-describe('Test "Sort Range Commands"', () => {
- let univer: Univer;
- let get: Injector['get'];
- let commandService: ICommandService;
- let sortService: SheetsSortUIService;
- let getValues: (
- startRow: number,
- startColumn: number,
- endRow: number,
- endColumn: number
- ) => Array<Array<Nullable<ICellData>>> | undefined;
-
- beforeEach(() => {
- const testBed = createCommandTestBed(undefined, [
- [IConfirmService, { useClass: TestConfirmService }],
- ]);
- univer = testBed.univer;
- get = testBed.get;
-
- commandService = get(ICommandService);
- commandService.registerCommand(ReorderRangeCommand);
- commandService.registerCommand(SetRangeValuesMutation);
- commandService.registerCommand(ReorderRangeMutation);
-
- sortService = get(SheetsSortUIService);
-
- getValues = (
- startRow: number,
- startColumn: number,
- endRow: number,
- endColumn: number
- ): Array<Array<Nullable<ICellData>>> | undefined =>
- get(IUniverInstanceService)
- .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)
- ?.getSheetBySheetId('sheet1')
- ?.getRange(startRow, startColumn, endRow, endColumn)
- .getValues();
- });
-
- afterEach(() => univer.dispose());
-
- describe('sort range has formula', () => {
- it('desc case: ', async () => {
- // J1
- let J1Cell = getValues(0, 9, 0, 9)?.[0]?.[0];
- expect(J1Cell?.v).toStrictEqual(1);
- // L1
- let L1Cell = getValues(0, 11, 0, 11)?.[0]?.[0];
- expect(L1Cell?.f).toStrictEqual('=J1/K1');
- // L7
- let L7Cell = getValues(6, 11, 6, 11)?.[0]?.[0];
- expect(L7Cell?.f).toStrictEqual('=SUM(J7:K8)');
-
- const selectionManager = get(SheetsSelectionsService);
- selectionManager.addSelections([
- {
- range: {
- startRow: 0,
- startColumn: 9,
- endRow: 6,
- endColumn: 11,
- rangeType: RANGE_TYPE.NORMAL,
- },
- primary: {
- actualRow: 0,
- actualColumn: 9,
- startRow: 0,
- startColumn: 9,
- endRow: 6,
- endColumn: 11,
- isMerged: false,
- isMergedMainCell: false,
- },
- style: null,
- },
- ]);
-
- const result = await sortService.triggerSortDirectly(false, false);
- expect(result).toBeTruthy();
-
- // J1
- J1Cell = getValues(0, 9, 0, 9)?.[0]?.[0];
- expect(J1Cell?.v).toStrictEqual(7);
- // L1
- L1Cell = getValues(0, 11, 0, 11)?.[0]?.[0];
- expect(L1Cell?.f).toStrictEqual('=SUM(J1:K2)');
- // L7
- L7Cell = getValues(6, 11, 6, 11)?.[0]?.[0];
- expect(L7Cell?.f).toStrictEqual('=J7/K7');
- });
- });
-});
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 2b874b77b5..129a3d6f64 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -2306,9 +2306,9 @@ importers:
'@univerjs-infra/shared':
specifier: workspace:*
version: link:../../common/shared
- '@univerjs/sheets-formula-ui':
+ '@univerjs/sheets-formula':
specifier: workspace:*
- version: link:../sheets-formula-ui
+ version: link:../sheets-formula
postcss:
specifier: ^8.5.28
version: 8.5.28