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: cell value should adjust rich text & function (#3385)
ybzkyca628e1f2b34
diff --git a/packages/sheets-ui/src/commands/commands/__tests__/add-worksheet-merge.command.spec.ts b/packages/sheets-ui/src/commands/commands/__tests__/add-worksheet-merge.command.spec.tsindex 8ce8ef02e6..fdf49a9a3d 100644--- a/packages/sheets-ui/src/commands/commands/__tests__/add-worksheet-merge.command.spec.ts+++ b/packages/sheets-ui/src/commands/commands/__tests__/add-worksheet-merge.command.spec.ts@@ -59,6 +59,7 @@ import {AddWorksheetMergeHorizontalCommand,AddWorksheetMergeVerticalCommand,} from '../add-worksheet-merge.command';+import { getClearContentMutationParamForRange } from '../../../common/utils';import { createCommandTestBed } from './create-command-test-bed';describe('Test add worksheet merge commands', () => {@@ -306,6 +307,96 @@ describe('Test add worksheet merge commands', () => {});});+ describe('merge cell with set cell data', () => {+ it('test clear util', () => {+ const commandService = get(ICommandService);+ const univerInstanceService = get(IUniverInstanceService);+ const workbook = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!;+ const worksheet = workbook.getActiveSheet();+ if (!worksheet) throw new Error('No active sheet found');++ commandService.executeCommand(SetRangeValuesMutation.id, {+ unitId: workbook.getUnitId(),+ subUnitId: worksheet.getSheetId(),+ cellValue: {+ 2: {+ 2: {+ p: {+ id: '__INTERNAL_EDITOR__DOCS_NORMAL',+ documentStyle: {+ pageSize: {+ width: 82.20805358886719,+ height: null,+ },+ marginTop: 0,+ marginBottom: 1,+ marginRight: 2,+ marginLeft: 2,+ renderConfig: {+ horizontalAlign: 0,+ verticalAlign: 0,+ centerAngle: 0,+ vertexAngle: 0,+ wrapStrategy: 0,+ },+ },+ body: {+ dataStream: 'hahaha\r\n',+ textRuns: [+ {+ st: 3,+ ed: 5,+ ts: {+ fs: 28,+ },+ },+ ],+ paragraphs: [+ {+ startIndex: 6,+ paragraphStyle: {+ horizontalAlign: 0,+ },+ },+ ],+ sectionBreaks: [+ {+ startIndex: 7,+ },+ ],+ customRanges: [],+ customDecorations: [],+ },+ drawings: {},+ drawingsOrder: [],+ settings: {+ zoomRatio: 1,+ },+ resources: [+ {+ name: 'SHEET_THREAD_COMMENT_PLUGIN',+ data: '{}',+ },+ {+ name: 'SHEET_AuthzIoMockService_PLUGIN',+ data: '{}',+ },+ ],+ },+ v: null,+ f: null,+ si: null,+ custom: {},+ },+ },+ },+ });+ const res = getClearContentMutationParamForRange(worksheet, { startRow: 0, startColumn: 2, endRow: 2, endColumn: 2 });+ expect(res.getValue(0, 2)?.p).toBeTruthy();+ expect(res.getValue(2, 2)).toBeNull();+ });+ });+describe('with insert or remove col', () => {it('will adjust the merge data when insert col and remove col', async () => {selectionManager.clearCurrentSelections();diff --git a/packages/sheets-ui/src/common/utils.ts b/packages/sheets-ui/src/common/utils.tsindex 273a73a294..aa0dd01820 100644--- a/packages/sheets-ui/src/common/utils.ts+++ b/packages/sheets-ui/src/common/utils.ts@@ -88,14 +88,14 @@ export function getClearContentMutationParamsForRanges(};}-function getClearContentMutationParamForRange(worksheet: Worksheet, range: IRange): ObjectMatrix<Nullable<ICellData>> {+export function getClearContentMutationParamForRange(worksheet: Worksheet, range: IRange): ObjectMatrix<Nullable<ICellData>> {const { startRow, startColumn, endColumn, endRow } = range;const cellMatrix = worksheet.getMatrixWithMergedCells(startRow, startColumn, endRow, endColumn, true);const redoMatrix = new ObjectMatrix<Nullable<ICellData>>();let leftTopCellValue: Nullable<ICellData> = null;cellMatrix.forValue((row, col, cellData) => {if (cellData) {- if (!leftTopCellValue && cellData.v !== undefined) {+ if (!leftTopCellValue && worksheet.cellHasValue(cellData)) {leftTopCellValue = cellData;}redoMatrix.setValue(row, col, null);