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(formula): get dirtyRanges when row column removed (#4588)

Dushusir0e0d68bfb0d5
diff --git a/packages/core/src/shared/object-matrix.ts b/packages/core/src/shared/object-matrix.ts
index 9c3e9fac87..6e6d034d20 100644
--- a/packages/core/src/shared/object-matrix.ts
+++ b/packages/core/src/shared/object-matrix.ts
@@ -701,15 +701,6 @@ export class ObjectMatrix<T> {
return ranges;
}
- merge(newObject: ObjectMatrix<T>) {
- this.forValue((row, column) => {
- const cellValue = newObject.getValue(row, column);
- if (cellValue != null) {
- this.setValue(row, column, cellValue);
- }
- });
- }
-
private _setOriginValue(matrix: IObjectMatrixPrimitiveType<T> = {}) {
this._matrix = matrix;
}
diff --git a/packages/sheets-formula/src/controllers/active-dirty.controller.ts b/packages/sheets-formula/src/controllers/active-dirty.controller.ts
index d1094829ab..f8f7750775 100644
--- a/packages/sheets-formula/src/controllers/active-dirty.controller.ts
+++ b/packages/sheets-formula/src/controllers/active-dirty.controller.ts
@@ -17,7 +17,6 @@
import type { ICellData, ICommandInfo, IObjectMatrixPrimitiveType, IRange, IUnitRange, Nullable } from '@univerjs/core';
import type { IDirtyUnitSheetDefinedNameMap, IDirtyUnitSheetNameMap, ISetDefinedNameMutationParam } from '@univerjs/engine-formula';
import type {
- IDeleteRangeMutationParams,
IInsertColMutationParams,
IInsertRowMutationParams,
IInsertSheetMutationParams,
@@ -31,7 +30,6 @@ import type {
ISetRangeValuesMutationParams,
} from '@univerjs/sheets';
import {
- Dimension,
Disposable,
Inject,
IUniverInstanceService,
@@ -335,52 +333,6 @@ export class ActiveDirtyController extends Disposable {
return dirtyRanges;
}
- private _getDeleteRangeMutationDirtyRange(params: IDeleteRangeMutationParams) {
- const { subUnitId: sheetId, unitId, range, shiftDimension } = params;
-
- const dirtyRanges: IUnitRange[] = [];
-
- const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);
-
- const worksheet = workbook?.getSheetBySheetId(sheetId);
-
- const lastEndRow = worksheet?.getLastRowWithContent() || 0;
-
- const lastEndColumn = worksheet?.getLastColumnWithContent() || 0;
-
- const matrix = new ObjectMatrix<Nullable<ICellData>>();
-
- let newMatrix: Nullable<ObjectMatrix<Nullable<ICellData>>> = null;
- const { startRow, startColumn, endRow, endColumn } = range;
- if (shiftDimension === Dimension.ROWS) {
- newMatrix = this._rangeToMatrix({
- startRow,
- startColumn,
- endRow: lastEndRow,
- endColumn,
- });
- } else if (shiftDimension === Dimension.COLUMNS) {
- newMatrix = this._rangeToMatrix({
- startRow,
- startColumn,
- endRow,
- endColumn: lastEndColumn,
- });
- }
-
- if (newMatrix != null) {
- matrix.merge(newMatrix);
- }
-
- const matrixData = matrix.getData();
-
- dirtyRanges.push(...this._getDirtyRangesByCellValue(unitId, sheetId, matrixData));
-
- dirtyRanges.push(...this._getDirtyRangesForArrayFormula(unitId, sheetId, matrixData));
-
- return dirtyRanges;
- }
-
private _getRemoveRowOrColumnMutation(params: IRemoveRowsMutationParams, isRow: boolean = true) {
const { subUnitId: sheetId, unitId, range } = params;
@@ -394,20 +346,18 @@ export class ActiveDirtyController extends Disposable {
const columnCount = worksheet?.getColumnCount() || 0;
- const matrix = new ObjectMatrix<Nullable<ICellData>>();
-
- let newMatrix: Nullable<ObjectMatrix<Nullable<ICellData>>> = null;
+ let matrix: Nullable<ObjectMatrix<Nullable<ICellData>>> = null;
const { startRow, endRow, startColumn, endColumn } = range;
if (isRow === true) {
- newMatrix = this._rangeToMatrix({
+ matrix = this._rangeToMatrix({
startRow,
startColumn: 0,
endRow,
endColumn: columnCount - 1,
});
} else {
- newMatrix = this._rangeToMatrix({
+ matrix = this._rangeToMatrix({
startRow: 0,
startColumn,
endRow: rowCount,
@@ -415,10 +365,6 @@ export class ActiveDirtyController extends Disposable {
});
}
- if (newMatrix != null) {
- matrix.merge(newMatrix);
- }
-
const matrixData = matrix.getData();
dirtyRanges.push(...this._getDirtyRangesByCellValue(unitId, sheetId, matrixData));