Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixing the range of remove merged selection and filter empty ranges #1680

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading