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: clear content should not be set empty object (#4861)
ybzky33bc6bb488c3
diff --git a/packages/sheets-formula-ui/src/commands/operations/__tests__/insert-function.operation.spec.ts b/packages/sheets-formula-ui/src/commands/operations/__tests__/insert-function.operation.spec.tsindex f18715299a..e2b6779134 100644--- a/packages/sheets-formula-ui/src/commands/operations/__tests__/insert-function.operation.spec.ts+++ b/packages/sheets-formula-ui/src/commands/operations/__tests__/insert-function.operation.spec.ts@@ -87,7 +87,7 @@ describe('Test insert function operation', () => {expect(values?.[0]?.[0]?.si).toStrictEqual(values?.[1]?.[0]?.si);// undoexpect(await commandService.executeCommand(UndoCommand.id)).toBeTruthy();- expect(getValues()).toStrictEqual([[{}], [{}]]);+ expect(getValues()).toStrictEqual([[null], [null]]);// redoexpect(await commandService.executeCommand(RedoCommand.id)).toBeTruthy();values = getValues();@@ -124,7 +124,7 @@ describe('Test insert function operation', () => {expect(values?.[0]?.[0]?.si).toStrictEqual(values?.[0]?.[1]?.si);// undoexpect(await commandService.executeCommand(UndoCommand.id)).toBeTruthy();- expect(getValues()).toStrictEqual([[{}, {}]]);+ expect(getValues()).toStrictEqual([[null, null]]);// redoexpect(await commandService.executeCommand(RedoCommand.id)).toBeTruthy();values = getValues();diff --git a/packages/sheets-formula-ui/src/controllers/__tests__/formula-auto-fill.controller.spec.ts b/packages/sheets-formula-ui/src/controllers/__tests__/formula-auto-fill.controller.spec.tsindex caaee676a8..581cc1e6d4 100644--- a/packages/sheets-formula-ui/src/controllers/__tests__/formula-auto-fill.controller.spec.ts+++ b/packages/sheets-formula-ui/src/controllers/__tests__/formula-auto-fill.controller.spec.ts@@ -165,7 +165,7 @@ describe('Test auto fill with formula', () => {t: 2,v: 1,});- expect(B3).toStrictEqual({});+ expect(B3).toBeNull();// redoexpect(await commandService.executeCommand(RedoCommand.id)).toBeTruthy();@@ -258,12 +258,12 @@ describe('Test auto fill with formula', () => {D2 = values && values[1][2];D3 = values && values[2][2];- expect(C1).toStrictEqual({});- expect(C2).toStrictEqual({});- expect(C3).toStrictEqual({});- expect(D1).toStrictEqual({});- expect(D2).toStrictEqual({});- expect(D3).toStrictEqual({});+ expect(C1).toBeNull();+ expect(C2).toBeNull();+ expect(C3).toBeNull();+ expect(D1).toBeNull();+ expect(D2).toBeNull();+ expect(D3).toBeNull();// redoexpect(await commandService.executeCommand(RedoCommand.id)).toBeTruthy();@@ -339,9 +339,9 @@ describe('Test auto fill with formula', () => {A8 = values && values[1][0];A9 = values && values[2][0];- expect(A7).toStrictEqual({});- expect(A8).toStrictEqual({});- expect(A9).toStrictEqual({});+ expect(A7).toBeNull();+ expect(A8).toBeNull();+ expect(A9).toBeNull();// redoexpect(await commandService.executeCommand(RedoCommand.id)).toBeTruthy();@@ -410,10 +410,10 @@ describe('Test auto fill with formula', () => {A18 = values && values[2][0];A19 = values && values[3][0];- expect(A16).toStrictEqual({});- expect(A17).toStrictEqual({});- expect(A18).toStrictEqual({});- expect(A19).toStrictEqual({});+ expect(A16).toBeNull();+ expect(A17).toBeNull();+ expect(A18).toBeNull();+ expect(A19).toBeNull();// redoexpect(await commandService.executeCommand(RedoCommand.id)).toBeTruthy();diff --git a/packages/sheets-formula-ui/src/controllers/__tests__/update-formula.controller.spec.ts b/packages/sheets-formula-ui/src/controllers/__tests__/update-formula.controller.spec.tsindex 48e79396eb..3c85b1c905 100644--- a/packages/sheets-formula-ui/src/controllers/__tests__/update-formula.controller.spec.ts+++ b/packages/sheets-formula-ui/src/controllers/__tests__/update-formula.controller.spec.ts@@ -516,7 +516,7 @@ describe('Test update formula ', () => {expect(await commandService.executeCommand(MoveRangeCommand.id, params)).toBeTruthy();const values = getValues(5, 2, 5, 3);- expect(values).toStrictEqual([[{}, { f: '=SUM(A1:B2)' }]]);+ expect(values).toStrictEqual([[null, { f: '=SUM(A1:B2)' }]]);expect(await commandService.executeCommand(UndoCommand.id)).toBeTruthy();const valuesUndo = getValues(5, 2, 5, 3);@@ -524,7 +524,7 @@ describe('Test update formula ', () => {expect(await commandService.executeCommand(RedoCommand.id)).toBeTruthy();const valuesRedo = getValues(5, 2, 5, 3);- expect(valuesRedo).toStrictEqual([[{}, { f: '=SUM(A1:B2)' }]]);+ expect(valuesRedo).toStrictEqual([[null, { f: '=SUM(A1:B2)' }]]);});it('Move range, update reference with si ', async () => {@@ -547,15 +547,15 @@ describe('Test update formula ', () => {expect(await commandService.executeCommand(MoveRangeCommand.id, params)).toBeTruthy();const values = getValues(18, 1, 20, 2);- expect(values).toStrictEqual([[{}, { f: '=SUM(A19)', t: 2, v: 1 }], [{}, { f: '=SUM(A20)', si: 'id1', t: 2, v: 2 }], [{}, { si: 'id1', t: 2, v: 3 }]]);+ expect(values).toStrictEqual([[null, { f: '=SUM(A19)', t: 2, v: 1 }], [null, { f: '=SUM(A20)', si: 'id1', t: 2, v: 2 }], [null, { si: 'id1', t: 2, v: 3 }]]);expect(await commandService.executeCommand(UndoCommand.id)).toBeTruthy();const valuesUndo = getValues(18, 1, 20, 2);- expect(valuesUndo).toStrictEqual([[{ f: '=SUM(A19)', t: 2, v: 1 }, {}], [{ f: '=SUM(A20)', si: 'id1', t: 2, v: 2 }, {}], [{ si: 'id1', t: 2, v: 3 }, {}]]);+ expect(valuesUndo).toStrictEqual([[{ f: '=SUM(A19)', t: 2, v: 1 }, null], [{ f: '=SUM(A20)', si: 'id1', t: 2, v: 2 }, null], [{ si: 'id1', t: 2, v: 3 }, null]]);expect(await commandService.executeCommand(RedoCommand.id)).toBeTruthy();const valuesRedo = getValues(18, 1, 20, 2);- expect(valuesRedo).toStrictEqual([[{}, { f: '=SUM(A19)', t: 2, v: 1 }], [{}, { f: '=SUM(A20)', si: 'id1', t: 2, v: 2 }], [{}, { si: 'id1', t: 2, v: 3 }]]);+ expect(valuesRedo).toStrictEqual([[null, { f: '=SUM(A19)', t: 2, v: 1 }], [null, { f: '=SUM(A20)', si: 'id1', t: 2, v: 2 }], [null, { si: 'id1', t: 2, v: 3 }]]);});it('Move rows, update reference', async () => {@@ -630,7 +630,7 @@ describe('Test update formula ', () => {expect(await commandService.executeCommand(MoveRowsCommand.id, params)).toBeTruthy();const values = getValues(1, 2, 2, 2);- expect(values).toStrictEqual([[{ f: '=A1:B9' }], [{}]]);+ expect(values).toStrictEqual([[{ f: '=A1:B9' }], [null]]);const values2 = getValues(4, 2, 5, 2);expect(values2).toStrictEqual([[{ f: '=SUM(A1:B9)' }], [{ v: 1, t: CellValueType.NUMBER }]]);@@ -642,7 +642,7 @@ describe('Test update formula ', () => {expect(await commandService.executeCommand(RedoCommand.id)).toBeTruthy();const valuesRedo = getValues(1, 2, 2, 2);- expect(valuesRedo).toStrictEqual([[{ f: '=A1:B9' }], [{}]]);+ expect(valuesRedo).toStrictEqual([[{ f: '=A1:B9' }], [null]]);const valuesRedo2 = getValues(4, 2, 5, 2);expect(valuesRedo2).toStrictEqual([[{ f: '=SUM(A1:B9)' }], [{ v: 1, t: CellValueType.NUMBER }]]);});@@ -768,7 +768,7 @@ describe('Test update formula ', () => {expect(await commandService.executeCommand(MoveColsCommand.id, params)).toBeTruthy();const values = getValues(2, 1, 2, 2);- expect(values).toStrictEqual([[{ f: '=A1:I2' }, {}]]);+ expect(values).toStrictEqual([[{ f: '=A1:I2' }, null]]);const values2 = getValues(5, 1, 5, 2);expect(values2).toStrictEqual([[{ f: '=SUM(A1:I2)' }, { v: 1, t: CellValueType.NUMBER }]]);@@ -780,7 +780,7 @@ describe('Test update formula ', () => {expect(await commandService.executeCommand(RedoCommand.id)).toBeTruthy();const valuesRedo = getValues(2, 1, 2, 2);- expect(valuesRedo).toStrictEqual([[{ f: '=A1:I2' }, {}]]);+ expect(valuesRedo).toStrictEqual([[{ f: '=A1:I2' }, null]]);const valuesRedo2 = getValues(5, 1, 5, 2);expect(valuesRedo2).toStrictEqual([[{ f: '=SUM(A1:I2)' }, { v: 1, t: CellValueType.NUMBER }]]);});@@ -910,7 +910,7 @@ describe('Test update formula ', () => {expect(await commandService.executeCommand(UndoCommand.id)).toBeTruthy();const valuesUndo = getValues(10, 0, 13, 0);- expect(valuesUndo).toStrictEqual([[{ f: '=SUM(A8)' }], [{ f: '=SUM(A9)' }], [{ f: '=SUM(A10)' }], [{}]]);+ expect(valuesUndo).toStrictEqual([[{ f: '=SUM(A8)' }], [{ f: '=SUM(A9)' }], [{ f: '=SUM(A10)' }], [null]]);expect(await commandService.executeCommand(RedoCommand.id)).toBeTruthy();const valuesRedo = getValues(10, 0, 13, 0);@@ -972,7 +972,7 @@ describe('Test update formula ', () => {const valuesUndo2 = getValues(5, 2, 5, 3);expect(valuesUndo2).toStrictEqual([[{ f: '=SUM(A1:B2)' }, { v: 1, t: CellValueType.NUMBER }]]);const valuesUndo3 = getValues(7, 2, 7, 6);- expect(valuesUndo3).toStrictEqual([[{ v: 1, t: CellValueType.NUMBER }, { f: '=SUM(A8)' }, { f: '=SUM(B8)' }, { f: '=SUM(C8)' }, {}]]);+ expect(valuesUndo3).toStrictEqual([[{ v: 1, t: CellValueType.NUMBER }, { f: '=SUM(A8)' }, { f: '=SUM(B8)' }, { f: '=SUM(C8)' }, null]]);expect(await commandService.executeCommand(RedoCommand.id)).toBeTruthy();const valuesRedo = getValues(2, 2, 2, 3);@@ -1018,7 +1018,7 @@ describe('Test update formula ', () => {expect(await commandService.executeCommand(RemoveRowCommand.id, params)).toBeTruthy();const values = getValues(1, 2, 2, 2);- expect(values).toStrictEqual([[{ f: '=A1:B1' }], [{}]]);+ expect(values).toStrictEqual([[{ f: '=A1:B1' }], [null]]);const values2 = getValues(4, 2, 5, 2);expect(values2).toStrictEqual([[{ f: '=SUM(A1:B1)' }], [{ v: 1, t: CellValueType.NUMBER }]]);@@ -1030,7 +1030,7 @@ describe('Test update formula ', () => {expect(await commandService.executeCommand(RedoCommand.id)).toBeTruthy();const valuesRedo = getValues(1, 2, 2, 2);- expect(valuesRedo).toStrictEqual([[{ f: '=A1:B1' }], [{}]]);+ expect(valuesRedo).toStrictEqual([[{ f: '=A1:B1' }], [null]]);const valuesRedo2 = getValues(4, 2, 5, 2);expect(valuesRedo2).toStrictEqual([[{ f: '=SUM(A1:B1)' }], [{ v: 1, t: CellValueType.NUMBER }]]);});@@ -1047,7 +1047,7 @@ describe('Test update formula ', () => {expect(await commandService.executeCommand(RemoveRowCommand.id, params)).toBeTruthy();const values = getValues(9, 0, 12, 0);- expect(values).toStrictEqual([[{ f: '=SUM(A8)' }], [{ f: '=SUM(#REF!)' }], [{ f: '=SUM(A9)' }], [{}]]);+ expect(values).toStrictEqual([[{ f: '=SUM(A8)' }], [{ f: '=SUM(#REF!)' }], [{ f: '=SUM(A9)' }], [null]]);expect(await commandService.executeCommand(UndoCommand.id)).toBeTruthy();const valuesUndo = getValues(9, 0, 12, 0);@@ -1055,7 +1055,7 @@ describe('Test update formula ', () => {expect(await commandService.executeCommand(RedoCommand.id)).toBeTruthy();const valuesRedo = getValues(9, 0, 12, 0);- expect(valuesRedo).toStrictEqual([[{ f: '=SUM(A8)' }], [{ f: '=SUM(#REF!)' }], [{ f: '=SUM(A9)' }], [{}]]);+ expect(valuesRedo).toStrictEqual([[{ f: '=SUM(A8)' }], [{ f: '=SUM(#REF!)' }], [{ f: '=SUM(A9)' }], [null]]);});it('Remove row, removed row contains formula', async () => {@@ -1152,11 +1152,11 @@ describe('Test update formula ', () => {expect(await commandService.executeCommand(RemoveColCommand.id, params)).toBeTruthy();const values = getValues(2, 1, 2, 2);- expect(values).toStrictEqual([[{ f: '=A1:A2' }, {}]]);+ expect(values).toStrictEqual([[{ f: '=A1:A2' }, null]]);const values2 = getValues(5, 1, 5, 2);expect(values2).toStrictEqual([[{ f: '=SUM(A1:A2)' }, { v: 1, t: CellValueType.NUMBER }]]);const values3 = getValues(7, 2, 7, 5);- expect(values3).toStrictEqual([[{ f: '=SUM(A8)' }, { f: '=SUM(#REF!)' }, { f: '=SUM(B8)' }, {}]]);+ expect(values3).toStrictEqual([[{ f: '=SUM(A8)' }, { f: '=SUM(#REF!)' }, { f: '=SUM(B8)' }, null]]);expect(await commandService.executeCommand(UndoCommand.id)).toBeTruthy();const valuesUndo = getValues(2, 1, 2, 2);@@ -1168,11 +1168,11 @@ describe('Test update formula ', () => {expect(await commandService.executeCommand(RedoCommand.id)).toBeTruthy();const valuesRedo = getValues(2, 1, 2, 2);- expect(valuesRedo).toStrictEqual([[{ f: '=A1:A2' }, {}]]);+ expect(valuesRedo).toStrictEqual([[{ f: '=A1:A2' }, null]]);const valuesRedo2 = getValues(5, 1, 5, 2);expect(valuesRedo2).toStrictEqual([[{ f: '=SUM(A1:A2)' }, { v: 1, t: CellValueType.NUMBER }]]);const valuesRedo3 = getValues(7, 2, 7, 5);- expect(valuesRedo3).toStrictEqual([[{ f: '=SUM(A8)' }, { f: '=SUM(#REF!)' }, { f: '=SUM(B8)' }, {}]]);+ expect(valuesRedo3).toStrictEqual([[{ f: '=SUM(A8)' }, { f: '=SUM(#REF!)' }, { f: '=SUM(B8)' }, null]]);});it('Remove column, update reference and position, contains #REF', async () => {@@ -1201,11 +1201,11 @@ describe('Test update formula ', () => {f: '=OFFSET(A1,1,1)',v: 1,t: 2,- }, {}, {}]]);+ }, null, null]]);expect(await commandService.executeCommand(UndoCommand.id)).toBeTruthy();const valuesUndo = getValues(21, 0, 21, 4);- expect(valuesUndo).toStrictEqual([[{ }, { }, {+ expect(valuesUndo).toStrictEqual([[null, null, {f: '=OFFSET(A1,1,1)',v: 0,t: 2,@@ -1234,7 +1234,7 @@ describe('Test update formula ', () => {f: '=OFFSET(A1,1,1)',v: 1,t: 2,- }, {}, {}]]);+ }, null, null]]);});it('Remove column, removed column contains formula', async () => {@@ -1273,7 +1273,7 @@ describe('Test update formula ', () => {expect(await commandService.executeCommand(DeleteRangeMoveLeftCommand.id, params)).toBeTruthy();const values = getValues(2, 1, 2, 2);- expect(values).toStrictEqual([[{ f: '=A1:B2' }, {}]]);+ expect(values).toStrictEqual([[{ f: '=A1:B2' }, null]]);expect(await commandService.executeCommand(UndoCommand.id)).toBeTruthy();const valuesUndo = getValues(2, 1, 2, 2);@@ -1281,7 +1281,7 @@ describe('Test update formula ', () => {expect(await commandService.executeCommand(RedoCommand.id)).toBeTruthy();const valuesRedo = getValues(2, 1, 2, 2);- expect(valuesRedo).toStrictEqual([[{ f: '=A1:B2' }, {}]]);+ expect(valuesRedo).toStrictEqual([[{ f: '=A1:B2' }, null]]);});it('Delete move left, value on the right', async () => {@@ -1345,7 +1345,7 @@ describe('Test update formula ', () => {expect(await commandService.executeCommand(DeleteRangeMoveUpCommand.id, params)).toBeTruthy();const values = getValues(1, 2, 2, 2);- expect(values).toStrictEqual([[{ f: '=A1:B2' }], [{}]]);+ expect(values).toStrictEqual([[{ f: '=A1:B2' }], [null]]);expect(await commandService.executeCommand(UndoCommand.id)).toBeTruthy();const valuesUndo = getValues(1, 2, 2, 2);@@ -1353,7 +1353,7 @@ describe('Test update formula ', () => {expect(await commandService.executeCommand(RedoCommand.id)).toBeTruthy();const valuesRedo = getValues(1, 2, 2, 2);- expect(valuesRedo).toStrictEqual([[{ f: '=A1:B2' }], [{}]]);+ expect(valuesRedo).toStrictEqual([[{ f: '=A1:B2' }], [null]]);});it('Delete move up, value on the bottom', async () => {@@ -1707,7 +1707,7 @@ describe('Test update formula ', () => {expect(await commandService.executeCommand(SetRangeValuesCommand.id, params)).toBeTruthy();const values = getValues(7, 8, 7, 9);- expect(values).toStrictEqual([[{ }, { f: '=SUM(C8:E10)', si: 'CarNau' }]]);+ expect(values).toStrictEqual([[null, { f: '=SUM(C8:E10)', si: 'CarNau' }]]);});it('hide row and show row', async () => {diff --git a/packages/sheets/src/commands/commands/__tests__/clear-selection.command.spec.ts b/packages/sheets/src/commands/commands/__tests__/clear-selection.command.spec.tsindex 60120ac240..99b7f62694 100644--- a/packages/sheets/src/commands/commands/__tests__/clear-selection.command.spec.ts+++ b/packages/sheets/src/commands/commands/__tests__/clear-selection.command.spec.ts@@ -86,7 +86,7 @@ describe('Test clear selection content commands', () => {}expect(await commandService.executeCommand(ClearSelectionContentCommand.id)).toBeTruthy();- expect(getValue()).toStrictEqual({});+ expect(getValue()).toStrictEqual(null);// undoexpect(await commandService.executeCommand(UndoCommand.id)).toBeTruthy();expect(getValue()).toStrictEqual({@@ -95,7 +95,7 @@ describe('Test clear selection content commands', () => {});// redoexpect(await commandService.executeCommand(RedoCommand.id)).toBeTruthy();- expect(getValue()).toStrictEqual({});+ expect(getValue()).toStrictEqual(null);// Restore the original dataexpect(await commandService.executeCommand(UndoCommand.id)).toBeTruthy();@@ -304,7 +304,7 @@ describe('Test clear selection content commands', () => {});expect(await commandService.executeCommand(ClearSelectionAllCommand.id)).toBeTruthy();- expect(getValue()).toStrictEqual({});+ expect(getValue()).toStrictEqual(null);// undoexpect(await commandService.executeCommand(UndoCommand.id)).toBeTruthy();expect(getStyle()).toStrictEqual({@@ -312,7 +312,7 @@ describe('Test clear selection content commands', () => {});// redoexpect(await commandService.executeCommand(RedoCommand.id)).toBeTruthy();- expect(getValue()).toStrictEqual({});+ expect(getValue()).toStrictEqual(null);});it('clear all with merged cells', async () => {const selectionManager = get(SheetsSelectionsService);@@ -372,7 +372,7 @@ describe('Test clear selection content commands', () => {// clear all with merged cellsexpect(await commandService.executeCommand(ClearSelectionAllCommand.id)).toBeTruthy();// clear formats- expect(getValue()).toStrictEqual({});+ expect(getValue()).toStrictEqual(null);// remove mergeexpect(getMerge()).toStrictEqual([]);@@ -386,7 +386,7 @@ describe('Test clear selection content commands', () => {]);// redoexpect(await commandService.executeCommand(RedoCommand.id)).toBeTruthy();- expect(getValue()).toStrictEqual({});+ expect(getValue()).toStrictEqual(null);expect(getMerge()).toStrictEqual([]);});});diff --git a/packages/sheets/src/commands/commands/__tests__/insert-range.command.spec.ts b/packages/sheets/src/commands/commands/__tests__/insert-range.command.spec.tsindex 2d3583b0a6..f426ff2dcc 100644--- a/packages/sheets/src/commands/commands/__tests__/insert-range.command.spec.ts+++ b/packages/sheets/src/commands/commands/__tests__/insert-range.command.spec.ts@@ -286,7 +286,7 @@ describe('Test insert range commands', () => {},]);expect(await commandService.executeCommand(InsertRangeMoveRightCommand.id)).toBeTruthy();- expect(getValueByPosition(0, 0, 0, 0)).toStrictEqual({});+ expect(getValueByPosition(0, 0, 0, 0)).toStrictEqual(null);expect(getValueByPosition(0, 1, 0, 1)).toStrictEqual({v: 'A1',});@@ -302,7 +302,7 @@ describe('Test insert range commands', () => {// redoexpect(await commandService.executeCommand(RedoCommand.id)).toBeTruthy();- expect(getValueByPosition(0, 0, 0, 0)).toStrictEqual({});+ expect(getValueByPosition(0, 0, 0, 0)).toStrictEqual(null);expect(getValueByPosition(0, 1, 0, 1)).toStrictEqual({v: 'A1',});@@ -321,7 +321,7 @@ describe('Test insert range commands', () => {expect(await commandService.executeCommand(InsertRangeMoveRightCommand.id)).toBeTruthy();// cell value- expect(getValueByPosition(0, 2, 0, 2)).toStrictEqual({});+ expect(getValueByPosition(0, 2, 0, 2)).toStrictEqual(null);expect(getValueByPosition(0, 3, 0, 3)).toStrictEqual({v: 'C1',});@@ -348,7 +348,7 @@ describe('Test insert range commands', () => {expect(await commandService.executeCommand(InsertRangeMoveRightCommand.id)).toBeTruthy();// cell value- expect(getValueByPosition(4, 2, 4, 2)).toStrictEqual({});+ expect(getValueByPosition(4, 2, 4, 2)).toStrictEqual(null);expect(getValueByPosition(4, 3, 4, 3)).toStrictEqual({v: 'C5',});@@ -401,7 +401,7 @@ describe('Test insert range commands', () => {]);expect(await commandService.executeCommand(InsertRangeMoveDownCommand.id)).toBeTruthy();- expect(getValueByPosition(0, 0, 0, 0)).toStrictEqual({});+ expect(getValueByPosition(0, 0, 0, 0)).toStrictEqual(null);expect(getValueByPosition(1, 0, 1, 0)).toStrictEqual({v: 'A1',});@@ -417,7 +417,7 @@ describe('Test insert range commands', () => {// redoexpect(await commandService.executeCommand(RedoCommand.id)).toBeTruthy();- expect(getValueByPosition(0, 0, 0, 0)).toStrictEqual({});+ expect(getValueByPosition(0, 0, 0, 0)).toStrictEqual(null);expect(getValueByPosition(1, 0, 1, 0)).toStrictEqual({v: 'A1',});@@ -437,7 +437,7 @@ describe('Test insert range commands', () => {expect(await commandService.executeCommand(InsertRangeMoveDownCommand.id)).toBeTruthy();// cell value- expect(getValueByPosition(1, 6, 1, 6)).toStrictEqual({});+ expect(getValueByPosition(1, 6, 1, 6)).toStrictEqual(null);expect(getValueByPosition(2, 6, 2, 6)).toStrictEqual({v: 'G2',});@@ -469,7 +469,7 @@ describe('Test insert range commands', () => {expect(await commandService.executeCommand(InsertRangeMoveDownCommand.id)).toBeTruthy();// cell value- expect(getValueByPosition(1, 9, 1, 9)).toStrictEqual({});+ expect(getValueByPosition(1, 9, 1, 9)).toStrictEqual(null);expect(getValueByPosition(2, 9, 2, 9)).toStrictEqual({v: 'J2',});diff --git a/packages/sheets/src/commands/commands/__tests__/set-range-values.command.spec.ts b/packages/sheets/src/commands/commands/__tests__/set-range-values.command.spec.tsindex d000ccf94b..4ec349a5bf 100644--- a/packages/sheets/src/commands/commands/__tests__/set-range-values.command.spec.ts+++ b/packages/sheets/src/commands/commands/__tests__/set-range-values.command.spec.ts@@ -742,7 +742,7 @@ describe('Test set range values commands', () => {// undoexpect(await commandService.executeCommand(UndoCommand.id)).toBeTruthy();- expect(getValues(1, 1, 1, 4)).toStrictEqual([[{}, null, null, {}]]);+ expect(getValues(1, 1, 1, 4)).toStrictEqual([[null, null, null, null]]);// redoexpect(await commandService.executeCommand(RedoCommand.id)).toBeTruthy();@@ -900,7 +900,7 @@ describe('Test set range values commands', () => {// undoexpect(await commandService.executeCommand(UndoCommand.id)).toBeTruthy();- expect(getValues(0, 2, 0, 5)).toStrictEqual([[{ s: 's5' }, { s: 's5' }, {}, { v: 1, t: CellValueType.NUMBER }]]);+ expect(getValues(0, 2, 0, 5)).toStrictEqual([[{ s: 's5' }, { s: 's5' }, null, { v: 1, t: CellValueType.NUMBER }]]);// redoexpect(await commandService.executeCommand(RedoCommand.id)).toBeTruthy();diff --git a/packages/sheets/src/commands/mutations/set-range-values.mutation.ts b/packages/sheets/src/commands/mutations/set-range-values.mutation.tsindex 2e5799ad49..cabebd9d79 100644--- a/packages/sheets/src/commands/mutations/set-range-values.mutation.ts+++ b/packages/sheets/src/commands/mutations/set-range-values.mutation.ts@@ -23,6 +23,7 @@ import type {IObjectMatrixPrimitiveType,IRange,Nullable,+ Styles,Workbook,} from '@univerjs/core';import { CommandType, IUniverInstanceService, ObjectMatrix, Tools } from '@univerjs/core';@@ -123,50 +124,62 @@ export const SetRangeValuesMutation: IMutation<ISetRangeValuesMutationParams, bonewValues.forValue((row, col, newVal) => {// clear allif (!newVal) {- cellMatrix?.setValue(row, col, {});+ cellMatrix.realDeleteValue(row, col);} else {- const oldVal = cellMatrix.getValue(row, col) || {};+ let oldVal = cellMatrix.getValue(row, col) || {};+ oldVal = mergeCellData(newVal, oldVal, styles);- // NOTE: we may need to take `p` into account- const type = getCellType(styles, newVal, oldVal);-- if (newVal.f !== undefined) {- oldVal.f = newVal.f;- }-- if (newVal.si !== undefined) {- oldVal.si = newVal.si;- }-- if (newVal.p !== undefined) {- oldVal.p = newVal.p;- }-- // Set to null, clear content- if (newVal.v !== undefined) {- oldVal.v = getCellValue(type, newVal);- }-- if (oldVal.v !== undefined) {- oldVal.t = type;- // The text format may be set for the numeric cell, and cell.v needs to be converted to text- oldVal.v = getCellValue(type, oldVal);- }-- // handle style- if (newVal.s !== undefined) {- handleStyle(styles, oldVal, newVal);- }-- if (newVal.custom !== undefined) {- // Custom will overwrite the original value- oldVal.custom = newVal.custom;+ if (Tools.isEmptyObject(oldVal)) {+ cellMatrix.realDeleteValue(row, col);+ } else {+ cellMatrix.setValue(row, col, oldVal);}-- cellMatrix.setValue(row, col, Tools.removeNull(oldVal));}});return true;},};++function mergeCellData(newValue: ICellData, oldValue: ICellData, styles: Styles) {+ const overwriteCellPropertiesSet = new Set(['f', 'p', 'si', 'custom']);+ const type = getCellType(styles, newValue, oldValue);+ Object.keys(newValue).forEach((key) => {+ const cellPropertyKey = key as keyof ICellData;+ if (overwriteCellPropertiesSet.has(cellPropertyKey)) {+ const propertyValue = newValue[cellPropertyKey];+ updateCellProperty(oldValue, cellPropertyKey, propertyValue);+ } else if (cellPropertyKey === 'v') {+ if (newValue.v !== undefined) {+ oldValue.v = getCellValue(type, newValue);+ }+ } else if (cellPropertyKey === 's') {+ handleStyle(styles, oldValue, newValue);+ }+ });++ if (oldValue.v !== undefined) {+ oldValue.t = type;+ oldValue.v = getCellValue(type, oldValue);+ }+ if (oldValue.v === null) {+ delete oldValue.t;+ delete oldValue.v;+ }++ return oldValue;+}++function updateCellProperty<K extends keyof ICellData>(+ cell: ICellData,+ key: K,+ value: ICellData[K]+): void {+ if (value === undefined) {+ // Do nothing if the value is undefined+ } else if (value === null) {+ delete cell[key];+ } else {+ cell[key] = value;+ }+}