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(paste): optimize copy and paste mutations (#6472)

wpxp123456b463fef769b4
diff --git a/packages/sheets-ui/src/controllers/clipboard/utils.ts b/packages/sheets-ui/src/controllers/clipboard/utils.ts
index e69a572211..e85917ee67 100644
--- a/packages/sheets-ui/src/controllers/clipboard/utils.ts
+++ b/packages/sheets-ui/src/controllers/clipboard/utils.ts
@@ -672,24 +672,26 @@ export function getClearAndSetMergeMutations(
Rectangle.intersects({ startRow, startColumn, endRow, endColumn }, rect)
);
- const removeMergeMutationParams: IRemoveWorksheetMergeMutationParams = {
- unitId,
- subUnitId,
- ranges: mergedCellsInRange,
- };
- redoMutationsInfo.push({
- id: RemoveWorksheetMergeMutation.id,
- params: removeMergeMutationParams,
- });
+ if (mergedCellsInRange.length > 0) {
+ const removeMergeMutationParams: IRemoveWorksheetMergeMutationParams = {
+ unitId,
+ subUnitId,
+ ranges: mergedCellsInRange,
+ };
+ redoMutationsInfo.push({
+ id: RemoveWorksheetMergeMutation.id,
+ params: removeMergeMutationParams,
+ });
- const undoRemoveMergeMutationParams: IAddWorksheetMergeMutationParams = RemoveMergeUndoMutationFactory(
- accessor,
- removeMergeMutationParams
- );
- undoMutationsInfo.push({
- id: AddWorksheetMergeMutation.id,
- params: undoRemoveMergeMutationParams,
- });
+ const undoRemoveMergeMutationParams: IAddWorksheetMergeMutationParams = RemoveMergeUndoMutationFactory(
+ accessor,
+ removeMergeMutationParams
+ );
+ undoMutationsInfo.push({
+ id: AddWorksheetMergeMutation.id,
+ params: undoRemoveMergeMutationParams,
+ });
+ }
}
if (mergeRangeData.length > 0) {
diff --git a/packages/sheets-ui/src/services/clipboard/clipboard.service.ts b/packages/sheets-ui/src/services/clipboard/clipboard.service.ts
index ab4cbb8c7d..7d77fbee1f 100644
--- a/packages/sheets-ui/src/services/clipboard/clipboard.service.ts
+++ b/packages/sheets-ui/src/services/clipboard/clipboard.service.ts
@@ -930,6 +930,8 @@ export class SheetClipboardService extends Disposable implements ISheetClipboard
}
const rowManager = worksheet.getRowManager();
+ const defaultRowHeight = worksheet.getConfig().defaultRowHeight;
+
const { rows, cols } = pastedRange;
const pasteRangeStartRow = rows[0];
const pasteRangeEndRow = rows[rows.length - 1];
@@ -948,7 +950,7 @@ export class SheetClipboardService extends Disposable implements ISheetClipboard
startColumn: pasteRangeStartColumn,
endColumn: pasteRangeEndColumn,
},
- ]);
+ ]).filter((info) => info.autoHeight !== defaultRowHeight);
needAutoHeight.push(...autoHeight);
}
}