Skip to content

Commit

Permalink
fix: fixing the range of remove merged selection and filter empty ran…
Browse files Browse the repository at this point in the history
…ges (#1680)
  • Loading branch information
ybzky committed Mar 25, 2024
1 parent ab8a548 commit 117cbbe
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
Expand Up @@ -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';

Expand Down Expand Up @@ -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) {
Expand Down
20 changes: 12 additions & 8 deletions packages/sheets-ui/src/controllers/clipboard/utils.ts
Expand Up @@ -505,21 +505,25 @@ 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(
accessor,
addMergeMutationParams
);

undoMutationsInfo.push({
id: RemoveWorksheetMergeMutation.id,
params: undoAddMergeMutation,
});
if (mergeRangeData.length > 0) {
undoMutationsInfo.push({
id: RemoveWorksheetMergeMutation.id,
params: undoAddMergeMutation,
});
}

return { undos: undoMutationsInfo, redos: redoMutationsInfo };
}
Expand Down
Expand Up @@ -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;
}
Expand Down

0 comments on commit 117cbbe

Please sign in to comment.