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: fixing the range of remove merged selection and filter empty ranges (#1680)

ybzky117cbbefbf86
diff --git a/packages/sheets-ui/src/commands/commands/add-worksheet-merge.command.ts b/packages/sheets-ui/src/commands/commands/add-worksheet-merge.command.ts
index 9089bccb96..77626027d4 100644
--- a/packages/sheets-ui/src/commands/commands/add-worksheet-merge.command.ts
+++ b/packages/sheets-ui/src/commands/commands/add-worksheet-merge.command.ts
@@ -32,7 +32,8 @@ import {
AddWorksheetMergeMutation,
getAddMergeMutationRangeByType,
RemoveMergeUndoMutationFactory,
- RemoveWorksheetMergeMutation, SelectionManagerService } from '@univerjs/sheets';
+ RemoveWorksheetMergeMutation, SelectionManagerService,
+} from '@univerjs/sheets';
import { IConfirmService } from '@univerjs/ui';
import type { IAccessor } from '@wendellhu/redi';
@@ -94,14 +95,21 @@ export const AddWorksheetMergeCommand: ICommand = {
subUnitId,
ranges,
};
- redoMutations.push({ id: RemoveWorksheetMergeMutation.id, params: removeMergeMutationParams });
- redoMutations.push({ id: AddWorksheetMergeMutation.id, params: addMergeMutationParams });
// prepare undo mutations
const undoRemoveMergeMutationParams = RemoveMergeUndoMutationFactory(accessor, removeMergeMutationParams);
const undoMutationParams = AddMergeUndoMutationFactory(accessor, addMergeMutationParams);
+
+ // params should be the merged cells to be deleted accurately, rather than the selection
+ if (undoRemoveMergeMutationParams.ranges.length > 0) {
+ redoMutations.push({ id: RemoveWorksheetMergeMutation.id, params: undoRemoveMergeMutationParams });
+ }
+
+ redoMutations.push({ id: AddWorksheetMergeMutation.id, params: addMergeMutationParams });
undoMutations.push({ id: RemoveWorksheetMergeMutation.id, params: undoMutationParams });
- undoMutations.push({ id: AddWorksheetMergeMutation.id, params: undoRemoveMergeMutationParams });
+ if (undoRemoveMergeMutationParams.ranges.length > 0) {
+ undoMutations.push({ id: AddWorksheetMergeMutation.id, params: undoRemoveMergeMutationParams });
+ }
// add set range values mutations to undo redo mutations
if (willClearSomeCell) {
diff --git a/packages/sheets-ui/src/controllers/clipboard/utils.ts b/packages/sheets-ui/src/controllers/clipboard/utils.ts
index dc4238a533..16de4aad51 100644
--- a/packages/sheets-ui/src/controllers/clipboard/utils.ts
+++ b/packages/sheets-ui/src/controllers/clipboard/utils.ts
@@ -505,10 +505,12 @@ export function getClearAndSetMergeMutations(
subUnitId,
ranges: mergeRangeData,
};
- redoMutationsInfo.push({
- id: AddWorksheetMergeMutation.id,
- params: addMergeMutationParams,
- });
+ if (mergeRangeData.length > 0) {
+ redoMutationsInfo.push({
+ id: AddWorksheetMergeMutation.id,
+ params: addMergeMutationParams,
+ });
+ }
// undo
const undoAddMergeMutation: IRemoveWorksheetMergeMutationParams = AddMergeUndoMutationFactory(
@@ -516,10 +518,12 @@ export function getClearAndSetMergeMutations(
addMergeMutationParams
);
- undoMutationsInfo.push({
- id: RemoveWorksheetMergeMutation.id,
- params: undoAddMergeMutation,
- });
+ if (mergeRangeData.length > 0) {
+ undoMutationsInfo.push({
+ id: RemoveWorksheetMergeMutation.id,
+ params: undoAddMergeMutation,
+ });
+ }
return { undos: undoMutationsInfo, redos: redoMutationsInfo };
}
diff --git a/packages/sheets/src/commands/commands/remove-worksheet-merge.command.ts b/packages/sheets/src/commands/commands/remove-worksheet-merge.command.ts
index 92d8e53801..7c528c1007 100644
--- a/packages/sheets/src/commands/commands/remove-worksheet-merge.command.ts
+++ b/packages/sheets/src/commands/commands/remove-worksheet-merge.command.ts
@@ -70,17 +70,18 @@ export const RemoveWorksheetMergeCommand: ICommand = {
});
if (!hasMerge) return false;
- const undoMutationParams: IAddWorksheetMergeMutationParams = RemoveMergeUndoMutationFactory(
+ const undoredoMutationParams: IAddWorksheetMergeMutationParams = RemoveMergeUndoMutationFactory(
accessor,
removeMergeMutationParams
);
- const result = commandService.syncExecuteCommand(RemoveWorksheetMergeMutation.id, removeMergeMutationParams);
+ const result = commandService.syncExecuteCommand(RemoveWorksheetMergeMutation.id, undoredoMutationParams);
if (result) {
undoRedoService.pushUndoRedo({
unitID: unitId,
- undoMutations: [{ id: AddWorksheetMergeMutation.id, params: undoMutationParams }],
- redoMutations: [{ id: RemoveWorksheetMergeMutation.id, params: removeMergeMutationParams }],
+ undoMutations: [{ id: AddWorksheetMergeMutation.id, params: undoredoMutationParams }],
+ // params should be the merged cells to be deleted accurately, rather than the selection
+ redoMutations: [{ id: RemoveWorksheetMergeMutation.id, params: undoredoMutationParams }],
});
return true;
}