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): null-value will not unexpected deleted when moving row/cols (#1691)
YuHong1a1f7c89cf56
diff --git a/packages/core/src/shared/__test__/object-matrix.spec.ts b/packages/core/src/shared/__test__/object-matrix.spec.tsindex db51cc7667..341bd010ee 100644--- a/packages/core/src/shared/__test__/object-matrix.spec.ts+++ b/packages/core/src/shared/__test__/object-matrix.spec.ts@@ -24,6 +24,10 @@ describe('test ObjectMatrix', () => {2: { 1: '111', 2: '121', 3: '313' },});+ const getHasNullPrimitiveObj = () => ({+ 1: '111', 2: null, 3: '333',+ });+it('test deleteValue', () => {const matrix = new ObjectMatrix(getPrimitiveObj());matrix.realDeleteValue(1, 1);@@ -70,4 +74,20 @@ describe('test ObjectMatrix', () => {2: { 1: '123', 2: '222', 3: '333' },});});++ it('test moveMatrixArray, with null move backward in it', () => {+ const primitiveObject = getHasNullPrimitiveObj();+ moveMatrixArray(2, 1, 0, primitiveObject);+ expect(primitiveObject).toStrictEqual({+ 0: null, 2: '111', 3: '333',+ });+ });++ it('test moveMatrixArray, with null move forward in it', () => {+ const primitiveObject = getHasNullPrimitiveObj();+ moveMatrixArray(2, 1, 4, primitiveObject);+ expect(primitiveObject).toStrictEqual({+ 1: '111', 2: '333', 3: null,+ });+ });});diff --git a/packages/core/src/shared/object-matrix.ts b/packages/core/src/shared/object-matrix.tsindex fbc8c0824c..89dd11a1b6 100644--- a/packages/core/src/shared/object-matrix.ts+++ b/packages/core/src/shared/object-matrix.ts@@ -190,7 +190,7 @@ function _moveBackward<T>(array[i + count] = item;// Prevent undefined, otherwise the forValue loop will report an error- if (item == null) {+ if (item === undefined) {delete array[i + count];}}@@ -199,7 +199,7 @@ function _moveBackward<T>(toMove.forEach((item, index) => {array[toIndex + index] = item;- if (item == null) {+ if (item === undefined) {delete array[toIndex + index];}});@@ -225,7 +225,7 @@ function _moveForward<T>(array[i - count] = item;// Prevent undefined, otherwise the forValue loop will report an error- if (item == null) {+ if (item === undefined) {delete array[i - count];}}@@ -234,7 +234,7 @@ function _moveForward<T>(toMove.forEach((item, index) => {array[toIndex + index - count] = item;- if (item == null) {+ if (item === undefined) {delete array[toIndex + index - count];}});