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.

refactor(undoredo): refactor undo redo item interface for transforming (#409)

Wenzhao Hu6ca0b6e24930
diff --git a/packages/base-docs/src/commands/commands/core-editing.command.ts b/packages/base-docs/src/commands/commands/core-editing.command.ts
index 59f8f9e70f..0592a59514 100644
--- a/packages/base-docs/src/commands/commands/core-editing.command.ts
+++ b/packages/base-docs/src/commands/commands/core-editing.command.ts
@@ -73,11 +73,10 @@ export const InsertCommand: ICommand<IInsertCommandParams> = {
t: 'i',
body,
len: body.dataStream.length,
- line: 0, // FIXME: line shouldn't be 0 here?
+ line: 0,
segmentId,
});
- // TODO@wzhudev: prepare undo mutation
const result = commandService.syncExecuteCommand<
IRichTextEditingMutationParams,
IRichTextEditingMutationParams
@@ -86,12 +85,8 @@ export const InsertCommand: ICommand<IInsertCommandParams> = {
if (result) {
undoRedoService.pushUndoRedo({
unitID: unitId,
- undo() {
- return commandService.syncExecuteCommand(RichTextEditingMutation.id, result);
- },
- redo() {
- return commandService.syncExecuteCommand(RichTextEditingMutation.id, doMutation.params);
- },
+ undoMutations: [{ id: RichTextEditingMutation.id, params: result }],
+ redoMutations: [{ id: RichTextEditingMutation.id, params: doMutation.params }],
});
return true;
@@ -139,12 +134,8 @@ export const DeleteCommand: ICommand<IDeleteCommandParams> = {
if (result) {
undoRedoService.pushUndoRedo({
unitID: unitId,
- undo() {
- return commandService.syncExecuteCommand(RichTextEditingMutation.id, result);
- },
- redo() {
- return commandService.syncExecuteCommand(doMutation.id, doMutation.params);
- },
+ undoMutations: [{ id: RichTextEditingMutation.id, params: result }],
+ redoMutations: [{ id: RichTextEditingMutation.id, params: doMutation.params }],
});
return false;
}
@@ -200,7 +191,7 @@ export const UpdateCommand: ICommand<IUpdateCommandParams> = {
coverType,
});
- const result = await commandService.syncExecuteCommand<
+ const result = commandService.syncExecuteCommand<
IRichTextEditingMutationParams,
IRichTextEditingMutationParams
>(doMutation.id, doMutation.params);
@@ -208,14 +199,8 @@ export const UpdateCommand: ICommand<IUpdateCommandParams> = {
if (result) {
undoRedoService.pushUndoRedo({
unitID: unitId,
- undo() {
- commandService.syncExecuteCommand(RichTextEditingMutation.id, result);
- return true;
- },
- redo() {
- commandService.syncExecuteCommand(RichTextEditingMutation.id, doMutation.params);
- return true;
- },
+ undoMutations: [{ id: RichTextEditingMutation.id, params: result }],
+ redoMutations: [{ id: RichTextEditingMutation.id, params: doMutation.params }],
});
return true;
diff --git a/packages/base-docs/src/commands/commands/inline-format.command.ts b/packages/base-docs/src/commands/commands/inline-format.command.ts
index 9fa678c733..4a217a3332 100644
--- a/packages/base-docs/src/commands/commands/inline-format.command.ts
+++ b/packages/base-docs/src/commands/commands/inline-format.command.ts
@@ -184,12 +184,8 @@ export const SetInlineFormatCommand: ICommand<ISetInlineFormatCommandParams> = {
if (result) {
undoRedoService.pushUndoRedo({
unitID: unitId,
- undo() {
- return commandService.syncExecuteCommand(RichTextEditingMutation.id, result);
- },
- redo() {
- return commandService.syncExecuteCommand(doMutation.id, doMutation.params);
- },
+ undoMutations: [{ id: RichTextEditingMutation.id, params: result }],
+ redoMutations: [{ id: RichTextEditingMutation.id, params: doMutation.params }],
});
return true;
diff --git a/packages/base-docs/src/commands/commands/insert-floating-object.command.ts b/packages/base-docs/src/commands/commands/insert-floating-object.command.ts
index 9e1d5345de..70358873af 100644
--- a/packages/base-docs/src/commands/commands/insert-floating-object.command.ts
+++ b/packages/base-docs/src/commands/commands/insert-floating-object.command.ts
@@ -42,12 +42,8 @@ export const InsertDrawingCommand: ICommand = {
if (result) {
undoRedoService.pushUndoRedo({
unitID: documentId,
- undo() {
- return commandService.syncExecuteCommand(RemoveDrawingMutation.id, undoMutationParams);
- },
- redo() {
- return commandService.syncExecuteCommand(InsertDrawingMutation.id, redoMutationParams);
- },
+ undoMutations: [{ id: RemoveDrawingMutation.id, params: undoMutationParams }],
+ redoMutations: [{ id: InsertDrawingMutation.id, params: redoMutationParams }],
});
return true;
}
diff --git a/packages/base-docs/src/commands/commands/remove-floating-object.command.ts b/packages/base-docs/src/commands/commands/remove-floating-object.command.ts
index 3ea7202c1c..1ed29e75b8 100644
--- a/packages/base-docs/src/commands/commands/remove-floating-object.command.ts
+++ b/packages/base-docs/src/commands/commands/remove-floating-object.command.ts
@@ -43,12 +43,8 @@ export const RemoveDrawingCommand: ICommand = {
if (result) {
undoRedoService.pushUndoRedo({
unitID: documentId,
- undo() {
- return commandService.syncExecuteCommand(InsertDrawingMutation.id, undoMutationParams);
- },
- redo() {
- return commandService.syncExecuteCommand(RemoveDrawingMutation.id, redoMutationParams);
- },
+ undoMutations: [{ id: InsertDrawingMutation.id, params: undoMutationParams }],
+ redoMutations: [{ id: RemoveDrawingMutation.id, params: redoMutationParams }],
});
return true;
}
diff --git a/packages/base-docs/src/commands/commands/set-doc-zoom-ratio.command.ts b/packages/base-docs/src/commands/commands/set-doc-zoom-ratio.command.ts
index f40691c8ce..06bbcf1022 100644
--- a/packages/base-docs/src/commands/commands/set-doc-zoom-ratio.command.ts
+++ b/packages/base-docs/src/commands/commands/set-doc-zoom-ratio.command.ts
@@ -43,12 +43,8 @@ export const SetDocZoomRatioCommand: ICommand = {
if (result) {
undoRedoService.pushUndoRedo({
unitID: documentId,
- undo() {
- return commandService.syncExecuteCommand(SetDocZoomRatioOperation.id, undoMutationParams);
- },
- redo() {
- return commandService.syncExecuteCommand(SetDocZoomRatioOperation.id, setZoomRatioMutationParams);
- },
+ undoMutations: [{ id: SetDocZoomRatioOperation.id, params: undoMutationParams }],
+ redoMutations: [{ id: SetDocZoomRatioOperation.id, params: setZoomRatioMutationParams }],
});
return true;
}
diff --git a/packages/base-docs/src/commands/commands/set-floating-object-transform.command.ts b/packages/base-docs/src/commands/commands/set-floating-object-transform.command.ts
index 8f9ce1c8ee..40cf590c0a 100644
--- a/packages/base-docs/src/commands/commands/set-floating-object-transform.command.ts
+++ b/packages/base-docs/src/commands/commands/set-floating-object-transform.command.ts
@@ -57,12 +57,8 @@ export const SetDrawingSizeCommand: ICommand = {
if (result) {
undoRedoService.pushUndoRedo({
unitID: documentId,
- undo() {
- return commandService.syncExecuteCommand(SetDrawingTransformMutation.id, undoMutationParams);
- },
- redo() {
- return commandService.syncExecuteCommand(SetDrawingTransformMutation.id, redoMutationParams);
- },
+ undoMutations: [{ id: SetDrawingTransformMutation.id, params: undoMutationParams }],
+ redoMutations: [{ id: SetDrawingTransformMutation.id, params: redoMutationParams }],
});
return true;
}
@@ -114,12 +110,8 @@ export const SetDrawingPositionCommand: ICommand = {
if (result) {
undoRedoService.pushUndoRedo({
unitID: documentId,
- undo() {
- return commandService.syncExecuteCommand(SetDrawingTransformMutation.id, undoMutationParams);
- },
- redo() {
- return commandService.syncExecuteCommand(SetDrawingTransformMutation.id, redoMutationParams);
- },
+ undoMutations: [{ id: SetDrawingTransformMutation.id, params: undoMutationParams }],
+ redoMutations: [{ id: SetDrawingTransformMutation.id, params: redoMutationParams }],
});
return true;
}
diff --git a/packages/base-sheets/src/commands/commands/add-worksheet-merge.command.ts b/packages/base-sheets/src/commands/commands/add-worksheet-merge.command.ts
index 388261eba1..a58493ef7c 100644
--- a/packages/base-sheets/src/commands/commands/add-worksheet-merge.command.ts
+++ b/packages/base-sheets/src/commands/commands/add-worksheet-merge.command.ts
@@ -68,36 +68,14 @@ export const AddWorksheetMergeCommand: ICommand = {
if (result && removeResult) {
undoRedoService.pushUndoRedo({
unitID: workbookId,
- undo() {
- return (
- commandService.executeCommand(
- RemoveWorksheetMergeMutation.id,
- undoMutationParams
- ) as Promise<boolean>
- ).then((res) => {
- if (res)
- return commandService.executeCommand(
- AddWorksheetMergeMutation.id,
- undoRemoveMergeMutationParams
- );
- return false;
- });
- },
- redo() {
- return (
- commandService.executeCommand(
- RemoveWorksheetMergeMutation.id,
- removeMergeMutationParams
- ) as Promise<boolean>
- ).then((res) => {
- if (res)
- return commandService.syncExecuteCommand(
- AddWorksheetMergeMutation.id,
- addMergeMutationParams
- );
- return false;
- });
- },
+ undoMutations: [
+ { id: RemoveWorksheetMergeMutation.id, params: undoMutationParams },
+ { id: AddWorksheetMergeMutation.id, params: undoRemoveMergeMutationParams },
+ ],
+ redoMutations: [
+ { id: RemoveWorksheetMergeMutation.id, params: removeMergeMutationParams },
+ { id: AddWorksheetMergeMutation.id, params: addMergeMutationParams },
+ ],
});
return true;
}
diff --git a/packages/base-sheets/src/commands/commands/clear-selection-all.command.ts b/packages/base-sheets/src/commands/commands/clear-selection-all.command.ts
index a1db648ea1..ddf592bef4 100644
--- a/packages/base-sheets/src/commands/commands/clear-selection-all.command.ts
+++ b/packages/base-sheets/src/commands/commands/clear-selection-all.command.ts
@@ -114,8 +114,8 @@ export const ClearSelectionAllCommand: ICommand = {
// If there are multiple mutations that form an encapsulated project, they must be encapsulated in the same undo redo element.
// Hooks can be used to hook the code of external controllers to add new actions.
unitID: workbookId,
- undo: async () => sequenceExecute(sequenceExecuteUndoList, commandService).result,
- redo: async () => sequenceExecute(sequenceExecuteList, commandService).result,
+ undoMutations: sequenceExecuteUndoList,
+ redoMutations: sequenceExecuteList,
});
return true;
diff --git a/packages/base-sheets/src/commands/commands/clear-selection-content.command.ts b/packages/base-sheets/src/commands/commands/clear-selection-content.command.ts
index 4a2d86516e..b101d572da 100644
--- a/packages/base-sheets/src/commands/commands/clear-selection-content.command.ts
+++ b/packages/base-sheets/src/commands/commands/clear-selection-content.command.ts
@@ -56,12 +56,8 @@ export const ClearSelectionContentCommand: ICommand = {
// If there are multiple mutations that form an encapsulated project, they must be encapsulated in the same undo redo element.
// Hooks can be used to hook the code of external controllers to add new actions.
unitID: workbookId,
- undo() {
- return commandService.syncExecuteCommand(SetRangeValuesMutation.id, undoClearMutationParams);
- },
- redo() {
- return commandService.syncExecuteCommand(SetRangeValuesMutation.id, clearMutationParams);
- },
+ undoMutations: [{ id: SetRangeValuesMutation.id, params: undoClearMutationParams }],
+ redoMutations: [{ id: SetRangeValuesMutation.id, params: clearMutationParams }],
});
return true;
diff --git a/packages/base-sheets/src/commands/commands/clear-selection-format.command.ts b/packages/base-sheets/src/commands/commands/clear-selection-format.command.ts
index 1324a16725..9d7500d357 100644
--- a/packages/base-sheets/src/commands/commands/clear-selection-format.command.ts
+++ b/packages/base-sheets/src/commands/commands/clear-selection-format.command.ts
@@ -115,8 +115,8 @@ export const ClearSelectionFormatCommand: ICommand = {
// If there are multiple mutations that form an encapsulated project, they must be encapsulated in the same undo redo element.
// Hooks can be used to hook the code of external controllers to add new actions.
unitID: workbookId,
- undo: async () => sequenceExecute(sequenceExecuteUndoList, commandService).result,
- redo: async () => sequenceExecute(sequenceExecuteList, commandService).result,
+ undoMutations: sequenceExecuteUndoList,
+ redoMutations: sequenceExecuteList,
});
return true;
diff --git a/packages/base-sheets/src/commands/commands/copy-format-to-range.command.ts b/packages/base-sheets/src/commands/commands/copy-format-to-range.command.ts
index 1d194ece70..d69710b652 100644
--- a/packages/base-sheets/src/commands/commands/copy-format-to-range.command.ts
+++ b/packages/base-sheets/src/commands/commands/copy-format-to-range.command.ts
@@ -74,12 +74,8 @@ export const CopyFormatToRangeCommand: ICommand = {
if (result) {
undoRedoService.pushUndoRedo({
unitID: workbookId,
- undo() {
- return commandService.syncExecuteCommand(SetRangeStyleMutation.id, undoMutationParams);
- },
- redo() {
- return commandService.syncExecuteCommand(SetRangeStyleMutation.id, setRangeStyleMutationParams);
- },
+ undoMutations: [{ id: SetRangeStyleMutation.id, params: undoMutationParams }],
+ redoMutations: [{ id: SetRangeStyleMutation.id, params: setRangeStyleMutationParams }],
});
return true;
}
diff --git a/packages/base-sheets/src/commands/commands/copy-range-to.command.ts b/packages/base-sheets/src/commands/commands/copy-range-to.command.ts
index 896768fa0d..ad8544befa 100644
--- a/packages/base-sheets/src/commands/commands/copy-range-to.command.ts
+++ b/packages/base-sheets/src/commands/commands/copy-range-to.command.ts
@@ -74,12 +74,8 @@ export const CopyRangeToCommand: ICommand = {
if (result) {
undoRedoService.pushUndoRedo({
unitID: workbookId,
- undo() {
- return commandService.syncExecuteCommand(SetRangeValuesMutation.id, undoMutationParams);
- },
- redo() {
- return commandService.syncExecuteCommand(SetRangeValuesMutation.id, setRangeValuesMutationParams);
- },
+ undoMutations: [{ id: SetRangeValuesMutation.id, params: undoMutationParams }],
+ redoMutations: [{ id: SetRangeValuesMutation.id, params: setRangeValuesMutationParams }],
});
return true;
}
diff --git a/packages/base-sheets/src/commands/commands/copy-to-worksheet.command.ts b/packages/base-sheets/src/commands/commands/copy-to-worksheet.command.ts
index 807d35e538..c4d09706d9 100644
--- a/packages/base-sheets/src/commands/commands/copy-to-worksheet.command.ts
+++ b/packages/base-sheets/src/commands/commands/copy-to-worksheet.command.ts
@@ -57,22 +57,17 @@ export const CopySheetToCommand: ICommand = {
accessor,
setWorksheetConfigMutationParams
);
+
const result = commandService.syncExecuteCommand(
SetWorksheetConfigMutation.id,
setWorksheetConfigMutationParams
);
+
if (result) {
undoRedoService.pushUndoRedo({
unitID: workbookId,
- undo() {
- return commandService.syncExecuteCommand(SetWorksheetConfigMutation.id, undoMutationParams);
- },
- redo() {
- return commandService.executeCommand(
- SetWorksheetConfigMutation.id,
- setWorksheetConfigMutationParams
- );
- },
+ undoMutations: [{ id: SetWorksheetConfigMutation.id, params: undoMutationParams }],
+ redoMutations: [{ id: SetWorksheetConfigMutation.id, params: setWorksheetConfigMutationParams }],
});
return true;
}
diff --git a/packages/base-sheets/src/commands/commands/copy-values-to-range.command.ts b/packages/base-sheets/src/commands/commands/copy-values-to-range.command.ts
index 2eb664886b..617ed67448 100644
--- a/packages/base-sheets/src/commands/commands/copy-values-to-range.command.ts
+++ b/packages/base-sheets/src/commands/commands/copy-values-to-range.command.ts
@@ -74,15 +74,10 @@ export const CopyValuesToRangeCommand: ICommand = {
if (result) {
undoRedoService.pushUndoRedo({
unitID: workbookId,
- undo() {
- return commandService.syncExecuteCommand(SetRangeFormattedValueMutation.id, undoMutationParams);
- },
- redo() {
- return commandService.syncExecuteCommand(
- SetRangeFormattedValueMutation.id,
- setRangeFormattedValueMutationParams
- );
- },
+ undoMutations: [{ id: SetRangeFormattedValueMutation.id, params: undoMutationParams }],
+ redoMutations: [
+ { id: SetRangeFormattedValueMutation.id, params: setRangeFormattedValueMutationParams },
+ ],
});
return true;
}
diff --git a/packages/base-sheets/src/commands/commands/copy-worksheet.command.ts b/packages/base-sheets/src/commands/commands/copy-worksheet.command.ts
index 9c0124d3b6..c31803f04f 100644
--- a/packages/base-sheets/src/commands/commands/copy-worksheet.command.ts
+++ b/packages/base-sheets/src/commands/commands/copy-worksheet.command.ts
@@ -76,30 +76,14 @@ export const CopySheetCommand: ICommand = {
if (insertResult && result) {
undoRedoService.pushUndoRedo({
unitID: workbookId,
- undo() {
- return (
- commandService.executeCommand(
- SetWorksheetActivateMutation.id,
- undoMutationParams
- ) as Promise<boolean>
- ).then((res) => {
- if (res)
- return commandService.syncExecuteCommand(RemoveSheetMutation.id, removeSheetMutationParams);
- return false;
- });
- },
- redo() {
- return (
- commandService.executeCommand(
- SetWorksheetActivateMutation.id,
- setSheetActiveMutationParams
- ) as Promise<boolean>
- ).then((res) => {
- if (res)
- return commandService.syncExecuteCommand(InsertSheetMutation.id, insertSheetMutationParams);
- return false;
- });
- },
+ undoMutations: [
+ { id: SetWorksheetActivateMutation.id, params: undoMutationParams },
+ { id: RemoveSheetMutation.id, params: removeSheetMutationParams },
+ ],
+ redoMutations: [
+ { id: SetWorksheetActivateMutation.id, params: setSheetActiveMutationParams },
+ { id: InsertSheetMutation.id, params: insertSheetMutationParams },
+ ],
});
return true;
}
diff --git a/packages/base-sheets/src/commands/commands/delete-range-move-left.command.ts b/packages/base-sheets/src/commands/commands/delete-range-move-left.command.ts
index e45d90a2a9..8ecdd82d2f 100644
--- a/packages/base-sheets/src/commands/commands/delete-range-move-left.command.ts
+++ b/packages/base-sheets/src/commands/commands/delete-range-move-left.command.ts
@@ -74,15 +74,13 @@ export const DeleteRangeMoveLeftCommand: ICommand = {
redos.push(...sheetInterceptor.redos);
undos.push(...sheetInterceptor.undos);
// execute do mutations and add undo mutations to undo stack if completed
- const result = await sequenceExecute(redos, commandService).result;
+ const result = sequenceExecute(redos, commandService).result;
if (result) {
undoRedoService.pushUndoRedo({
- // 如果有多个 mutation 构成一个封装项目,那么要封装在同一个 undo redo element 里面
- // 通过勾子可以 hook 外部 controller 的代码来增加新的 action
unitID: workbookId,
- undo: async () => sequenceExecute(undos.reverse(), commandService).result,
- redo: async () => sequenceExecute(redos, commandService).result,
+ undoMutations: undos.reverse(),
+ redoMutations: redos,
});
return true;
diff --git a/packages/base-sheets/src/commands/commands/delete-range-move-up.command.ts b/packages/base-sheets/src/commands/commands/delete-range-move-up.command.ts
index 6edb61fd4f..ceed3cad76 100644
--- a/packages/base-sheets/src/commands/commands/delete-range-move-up.command.ts
+++ b/packages/base-sheets/src/commands/commands/delete-range-move-up.command.ts
@@ -77,11 +77,9 @@ export const DeleteRangeMoveUpCommand: ICommand = {
if (result) {
undoRedoService.pushUndoRedo({
- // 如果有多个 mutation 构成一个封装项目,那么要封装在同一个 undo redo element 里面
- // 通过勾子可以 hook 外部 controller 的代码来增加新的 action
unitID: workbookId,
- undo: async () => sequenceExecute(undos.reverse(), commandService).result,
- redo: async () => sequenceExecute(redos, commandService).result,
+ undoMutations: undos.reverse(),
+ redoMutations: redos,
});
return true;
diff --git a/packages/base-sheets/src/commands/commands/insert-range-move-down.command.ts b/packages/base-sheets/src/commands/commands/insert-range-move-down.command.ts
index 9e9d3d91d8..6e234bd461 100644
--- a/packages/base-sheets/src/commands/commands/insert-range-move-down.command.ts
+++ b/packages/base-sheets/src/commands/commands/insert-range-move-down.command.ts
@@ -170,8 +170,8 @@ export const InsertRangeMoveDownCommand: ICommand = {
if (result) {
undoRedoService.pushUndoRedo({
unitID: workbookId,
- undo: async () => sequenceExecute(undoMutations.reverse(), commandService).result,
- redo: async () => sequenceExecute(redoMutations, commandService).result,
+ undoMutations: undoMutations.reverse(),
+ redoMutations,
});
return true;
diff --git a/packages/base-sheets/src/commands/commands/insert-range-move-right.command.ts b/packages/base-sheets/src/commands/commands/insert-range-move-right.command.ts
index f6994f1d8e..53b9f21d8c 100644
--- a/packages/base-sheets/src/commands/commands/insert-range-move-right.command.ts
+++ b/packages/base-sheets/src/commands/commands/insert-range-move-right.command.ts
@@ -165,8 +165,8 @@ export const InsertRangeMoveRightCommand: ICommand = {
if (result.result) {
undoRedoService.pushUndoRedo({
unitID: workbookId,
- undo: async () => sequenceExecute(undoMutations.reverse(), commandService).result,
- redo: async () => sequenceExecute(redoMutations, commandService).result,
+ undoMutations: undoMutations.reverse(),
+ redoMutations,
});
return true;
diff --git a/packages/base-sheets/src/commands/commands/insert-row-col.command.ts b/packages/base-sheets/src/commands/commands/insert-row-col.command.ts
index 27fb00e32a..0fdb15290c 100644
--- a/packages/base-sheets/src/commands/commands/insert-row-col.command.ts
+++ b/packages/base-sheets/src/commands/commands/insert-row-col.command.ts
@@ -133,25 +133,18 @@ export const InsertRowCommand: ICommand = {
if (result.result) {
undoRedoService.pushUndoRedo({
unitID: params.workbookId,
- undo: async () =>
- sequenceExecute(
- [
- ...intercepted.undos,
- { id: DeleteRangeMutation.id, params: undoInsertRangeMutationParams },
- { id: RemoveRowMutation.id, params: undoRowInsertionParams },
- ],
- commandService
- ).result,
- redo: async () =>
- sequenceExecute(
- [
- { id: InsertRowMutation.id, params: insertRowParams },
- { id: InsertRangeMutation.id, params: insertRangeMutationParams },
- ...intercepted.redos,
- ],
- commandService
- ).result,
+ undoMutations: [
+ ...intercepted.undos,
+ { id: DeleteRangeMutation.id, params: undoInsertRangeMutationParams },
+ { id: RemoveRowMutation.id, params: undoRowInsertionParams },
+ ],
+ redoMutations: [
+ { id: InsertRowMutation.id, params: insertRowParams },
+ { id: InsertRangeMutation.id, params: insertRangeMutationParams },
+ ...intercepted.redos,
+ ],
});
+
return true;
}
@@ -335,27 +328,19 @@ export const InsertColCommand: ICommand<IInsertColCommandParams> = {
if (result.result) {
undoRedoService.pushUndoRedo({
unitID: params.workbookId,
- undo: async () =>
- sequenceExecute(
- [
- ...intercepted.undos,
- { id: DeleteRangeMutation.id, params: undoInsertRangeParams },
- {
- id: RemoveColMutation.id,
- params: undoColInsertionParams,
- },
- ],
- commandService
- ).result,
- redo: async () =>
- sequenceExecute(
- [
- { id: InsertColMutation.id, params: insertColParams },
- { id: InsertRangeMutation.id, params: insertRangeMutationParams },
- ...intercepted.redos,
- ],
- commandService
- ).result,
+ undoMutations: [
+ ...intercepted.undos,
+ { id: DeleteRangeMutation.id, params: undoInsertRangeParams },
+ {
+ id: RemoveColMutation.id,
+ params: undoColInsertionParams,
+ },
+ ],
+ redoMutations: [
+ { id: InsertColMutation.id, params: insertColParams },
+ { id: InsertRangeMutation.id, params: insertRangeMutationParams },
+ ...intercepted.redos,
+ ],
});
return true;
}
diff --git a/packages/base-sheets/src/commands/commands/insert-sheet.command.ts b/packages/base-sheets/src/commands/commands/insert-sheet.command.ts
index 8125986f1e..9b782afdbc 100644
--- a/packages/base-sheets/src/commands/commands/insert-sheet.command.ts
+++ b/packages/base-sheets/src/commands/commands/insert-sheet.command.ts
@@ -89,33 +89,14 @@ export const InsertSheetCommand: ICommand = {
if (result && activateResult) {
undoRedoService.pushUndoRedo({
unitID: workbookId,
- undo() {
- return (
- commandService.executeCommand(
- SetWorksheetActivateMutation.id,
- undoMutationParams
- ) as Promise<boolean>
- ).then((res) => {
- if (res)
- return commandService.syncExecuteCommand(RemoveSheetMutation.id, removeSheetMutationParams);
- return false;
- });
- },
- redo() {
- return (
- commandService.executeCommand(
- InsertSheetMutation.id,
- insertSheetMutationParams
- ) as Promise<boolean>
- ).then((res) => {
- if (res)
- return commandService.executeCommand(
- SetWorksheetActivateMutation.id,
- setSheetActiveMutationParams
- );
- return false;
- });
- },
+ undoMutations: [
+ { id: SetWorksheetActivateMutation.id, params: undoMutationParams },
+ { id: RemoveSheetMutation.id, params: removeSheetMutationParams },
+ ],
+ redoMutations: [
+ { id: InsertSheetMutation.id, params: insertSheetMutationParams },
+ { id: SetWorksheetActivateMutation.id, params: setSheetActiveMutationParams },
+ ],
});
return true;
diff --git a/packages/base-sheets/src/commands/commands/move-range.command.ts b/packages/base-sheets/src/commands/commands/move-range.command.ts
index 113a42ffdc..d452a059a2 100644
--- a/packages/base-sheets/src/commands/commands/move-range.command.ts
+++ b/packages/base-sheets/src/commands/commands/move-range.command.ts
@@ -108,8 +108,8 @@ export const MoveRangeCommand: ICommand = {
if (result) {
undoRedoService.pushUndoRedo({
unitID: workbookId,
- undo: async () => sequenceExecute(undos, commandService).result,
- redo: async () => sequenceExecute(redos, commandService).result,
+ undoMutations: undos,
+ redoMutations: redos,
});
return true;
}
diff --git a/packages/base-sheets/src/commands/commands/move-rows-cols.command.ts b/packages/base-sheets/src/commands/commands/move-rows-cols.command.ts
index ace2cac674..ffb405b274 100644
--- a/packages/base-sheets/src/commands/commands/move-rows-cols.command.ts
+++ b/packages/base-sheets/src/commands/commands/move-rows-cols.command.ts
@@ -180,32 +180,18 @@ export const MoveRowsCommand: ICommand<IMoveRowsCommandParams> = {
const undoRedoService = accessor.get(IUndoRedoService);
undoRedoService.pushUndoRedo({
unitID: workbookId,
- async undo() {
- // NOTE: This may be affect by collaboration programming. But in google sheet, the merged cells are reverted as well :(
- const undoResult = sequenceExecute(
- [
- { id: MoveRowsMutation.id, params: undoMoveRowsParams },
- { id: RemoveWorksheetMergeMutation.id, params: undoAddMergeParams },
- { id: AddWorksheetMergeMutation.id, params: undoRemoveMergeMutationParams },
- { id: SetSelectionsOperation.id, params: undoSetSelectionsParam },
- ],
- commandService
- );
-
- return undoResult.result;
- },
- async redo() {
- const redoResult = sequenceExecute(
- [
- { id: MoveRowsMutation.id, params: moveRowsParams },
- { id: RemoveWorksheetMergeMutation.id, params: removeMergeMutationParams },
- { id: AddWorksheetMergeMutation.id, params: addMergeParams },
- { id: SetSelectionsOperation.id, params: setSelectionsParam },
- ],
- commandService
- );
- return redoResult.result;
- },
+ undoMutations: [
+ { id: MoveRowsMutation.id, params: undoMoveRowsParams },
+ { id: RemoveWorksheetMergeMutation.id, params: undoAddMergeParams },
+ { id: AddWorksheetMergeMutation.id, params: undoRemoveMergeMutationParams },
+ { id: SetSelectionsOperation.id, params: undoSetSelectionsParam },
+ ],
+ redoMutations: [
+ { id: MoveRowsMutation.id, params: moveRowsParams },
+ { id: RemoveWorksheetMergeMutation.id, params: removeMergeMutationParams },
+ { id: AddWorksheetMergeMutation.id, params: addMergeParams },
+ { id: SetSelectionsOperation.id, params: setSelectionsParam },
+ ],
});
return true;
}
@@ -358,32 +344,18 @@ export const MoveColsCommand: ICommand<IMoveColsCommandParams> = {
const undoRedoService = accessor.get(IUndoRedoService);
undoRedoService.pushUndoRedo({
unitID: workbookId,
- async undo() {
- // NOTE: This may be affect by collaboration programming. But in google sheet, the merged cells are reverted as well :(
- const undoResult = sequenceExecute(
- [
- { id: MoveColsMutation.id, params: undoMoveColsParams },
- { id: RemoveWorksheetMergeMutation.id, params: undoAddMergeParams },
- { id: AddWorksheetMergeMutation.id, params: undoRemoveMergeMutationParams },
- { id: SetSelectionsOperation.id, params: undoSetSelectionsParam },
- ],
- commandService
- );
-
- return undoResult.result;
- },
- async redo() {
- const redoResult = sequenceExecute(
- [
- { id: MoveColsMutation.id, params: moveColsParams },
- { id: RemoveWorksheetMergeMutation.id, params: removeMergeMutationParams },
- { id: AddWorksheetMergeMutation.id, params: addMergeParams },
- { id: SetSelectionsOperation.id, params: setSelectionsParam },
- ],
- commandService
- );
- return redoResult.result;
- },
+ undoMutations: [
+ { id: MoveColsMutation.id, params: undoMoveColsParams },
+ { id: RemoveWorksheetMergeMutation.id, params: undoAddMergeParams },
+ { id: AddWorksheetMergeMutation.id, params: undoRemoveMergeMutationParams },
+ { id: SetSelectionsOperation.id, params: undoSetSelectionsParam },
+ ],
+ redoMutations: [
+ { id: MoveColsMutation.id, params: moveColsParams },
+ { id: RemoveWorksheetMergeMutation.id, params: removeMergeMutationParams },
+ { id: AddWorksheetMergeMutation.id, params: addMergeParams },
+ { id: SetSelectionsOperation.id, params: setSelectionsParam },
+ ],
});
return true;
}
diff --git a/packages/base-sheets/src/commands/commands/remove-row-col.command.ts b/packages/base-sheets/src/commands/commands/remove-row-col.command.ts
index 2959f30cc4..fcbc3622bd 100644
--- a/packages/base-sheets/src/commands/commands/remove-row-col.command.ts
+++ b/packages/base-sheets/src/commands/commands/remove-row-col.command.ts
@@ -109,30 +109,17 @@ export const RemoveRowCommand: ICommand = {
if (result.result) {
accessor.get(IUndoRedoService).pushUndoRedo({
unitID: workbookId,
- undo: async () => {
- const undoResult = sequenceExecute(
- [
- ...intercepted.undos,
-
- { id: InsertRowMutation.id, params: undoRemoveRowsParams },
- { id: InsertRangeMutation.id, params: undoDeleteRangeValueParams },
- ],
- commandService
- );
- return undoResult.result;
- },
- redo: async () => {
- const result = sequenceExecute(
- [
- { id: DeleteRangeMutation.id, params: deleteRangeValueParams },
- { id: RemoveRowMutation.id, params: removeRowsParams },
- ...intercepted.redos,
- ],
- commandService
- );
-
- return result.result;
- },
+ undoMutations: [
+ ...intercepted.undos,
+
+ { id: InsertRowMutation.id, params: undoRemoveRowsParams },
+ { id: InsertRangeMutation.id, params: undoDeleteRangeValueParams },
+ ],
+ redoMutations: [
+ { id: DeleteRangeMutation.id, params: deleteRangeValueParams },
+ { id: RemoveRowMutation.id, params: removeRowsParams },
+ ...intercepted.redos,
+ ],
});
return true;
}
@@ -212,28 +199,16 @@ export const RemoveColCommand: ICommand = {
const undoRedoService = accessor.get(IUndoRedoService);
undoRedoService.pushUndoRedo({
unitID: workbookId,
- undo: async () => {
- const undoResult = sequenceExecute(
- [
- ...intercepted.undos,
- { id: InsertColMutation.id, params: undoRemoveColParams },
- { id: InsertRangeMutation.id, params: undoRemoveRangeValuesParams },
- ],
- commandService
- );
- return undoResult.result;
- },
- redo: async () => {
- const result = sequenceExecute(
- [
- { id: RemoveColMutation.id, params: removeColParams },
- { id: DeleteRangeMutation.id, params: removeRangeValuesParams },
- ...intercepted.redos,
- ],
- commandService
- );
- return result.result;
- },
+ undoMutations: [
+ ...intercepted.undos,
+ { id: InsertColMutation.id, params: undoRemoveColParams },
+ { id: InsertRangeMutation.id, params: undoRemoveRangeValuesParams },
+ ],
+ redoMutations: [
+ { id: RemoveColMutation.id, params: removeColParams },
+ { id: DeleteRangeMutation.id, params: removeRangeValuesParams },
+ ...intercepted.redos,
+ ],
});
return true;
diff --git a/packages/base-sheets/src/commands/commands/remove-sheet.command.ts b/packages/base-sheets/src/commands/commands/remove-sheet.command.ts
index 170d546cf8..b64a179f20 100644
--- a/packages/base-sheets/src/commands/commands/remove-sheet.command.ts
+++ b/packages/base-sheets/src/commands/commands/remove-sheet.command.ts
@@ -74,36 +74,14 @@ export const RemoveSheetCommand: ICommand = {
if (result && activeResult) {
undoRedoService.pushUndoRedo({
unitID: workbookId,
- undo() {
- return (
- commandService.executeCommand(
- InsertSheetMutation.id,
- InsertSheetMutationParams
- ) as Promise<boolean>
- ).then((res) => {
- if (res)
- return commandService.syncExecuteCommand(
- SetWorksheetActivateMutation.id,
- activeMutationParams
- );
- return false;
- });
- },
- redo() {
- return (
- commandService.executeCommand(
- RemoveSheetMutation.id,
- RemoveSheetMutationParams
- ) as Promise<boolean>
- ).then((res) => {
- if (res)
- return commandService.executeCommand(
- SetWorksheetActivateMutation.id,
- activeSheetMutationParams
- );
- return false;
- });
- },
+ undoMutations: [
+ { id: InsertSheetMutation.id, params: InsertSheetMutationParams },
+ { id: SetWorksheetActivateMutation.id, params: activeMutationParams },
+ ],
+ redoMutations: [
+ { id: RemoveSheetMutation.id, params: RemoveSheetMutationParams },
+ { id: SetWorksheetActivateMutation.id, params: activeSheetMutationParams },
+ ],
});
return true;
diff --git a/packages/base-sheets/src/commands/commands/remove-worksheet-merge.command.ts b/packages/base-sheets/src/commands/commands/remove-worksheet-merge.command.ts
index 734703ab36..23adeedb28 100644
--- a/packages/base-sheets/src/commands/commands/remove-worksheet-merge.command.ts
+++ b/packages/base-sheets/src/commands/commands/remove-worksheet-merge.command.ts
@@ -69,15 +69,8 @@ export const RemoveWorksheetMergeCommand: ICommand = {
if (result) {
undoRedoService.pushUndoRedo({
unitID: workbookId,
- undo() {
- return commandService.syncExecuteCommand(AddWorksheetMergeMutation.id, undoMutationParams);
- },
- redo() {
- return commandService.syncExecuteCommand(
- RemoveWorksheetMergeMutation.id,
- removeMergeMutationParams
- );
- },
+ undoMutations: [{ id: AddWorksheetMergeMutation.id, params: undoMutationParams }],
+ redoMutations: [{ id: RemoveWorksheetMergeMutation.id, params: removeMergeMutationParams }],
});
return true;
}
diff --git a/packages/base-sheets/src/commands/commands/set-border-command.ts b/packages/base-sheets/src/commands/commands/set-border-command.ts
index 8979a02d3b..d5405239ae 100644
--- a/packages/base-sheets/src/commands/commands/set-border-command.ts
+++ b/packages/base-sheets/src/commands/commands/set-border-command.ts
@@ -378,18 +378,9 @@ export const SetBorderCommand: ICommand = {
const result = commandService.syncExecuteCommand(SetBorderStylesMutation.id, setBorderStylesMutationParams);
if (result) {
undoRedoService.pushUndoRedo({
- // 如果有多个 mutation 构成一个封装项目,那么要封装在同一个 undo redo element 里面
- // 通过勾子可以 hook 外部 controller 的代码来增加新的 action
unitID: workbookId,
- undo() {
- return commandService.syncExecuteCommand(
- SetBorderStylesMutation.id,
- undoSetBorderStylesMutationParams
- );
- },
- redo() {
- return commandService.syncExecuteCommand(SetBorderStylesMutation.id, setBorderStylesMutationParams);
- },
+ undoMutations: [{ id: SetBorderStylesMutation.id, params: undoSetBorderStylesMutationParams }],
+ redoMutations: [{ id: SetBorderStylesMutation.id, params: setBorderStylesMutationParams }],
});
return true;
diff --git a/packages/base-sheets/src/commands/commands/set-border-styles-command.ts b/packages/base-sheets/src/commands/commands/set-border-styles-command.ts
index c73a3caae3..ebafbd41a5 100644
--- a/packages/base-sheets/src/commands/commands/set-border-styles-command.ts
+++ b/packages/base-sheets/src/commands/commands/set-border-styles-command.ts
@@ -364,18 +364,9 @@ export const SetBorderCommand: ICommand = {
const result = commandService.syncExecuteCommand(SetBorderStylesMutation.id, setBorderStylesMutationParams);
if (result) {
undoRedoService.pushUndoRedo({
- // 如果有多个 mutation 构成一个封装项目,那么要封装在同一个 undo redo element 里面
- // 通过勾子可以 hook 外部 controller 的代码来增加新的 action
unitID: workbookId,
- undo() {
- return commandService.syncExecuteCommand(
- SetBorderStylesMutation.id,
- undoSetBorderStylesMutationParams
- );
- },
- redo() {
- return commandService.syncExecuteCommand(SetBorderStylesMutation.id, setBorderStylesMutationParams);
- },
+ undoMutations: [{ id: SetBorderStylesMutation.id, params: undoSetBorderStylesMutationParams }],
+ redoMutations: [{ id: SetBorderStylesMutation.id, params: setBorderStylesMutationParams }],
});
return true;
diff --git a/packages/base-sheets/src/commands/commands/set-col-visible.command.ts b/packages/base-sheets/src/commands/commands/set-col-visible.command.ts
index 1a813d0918..13c89e8640 100644
--- a/packages/base-sheets/src/commands/commands/set-col-visible.command.ts
+++ b/packages/base-sheets/src/commands/commands/set-col-visible.command.ts
@@ -76,25 +76,14 @@ export const SetSpecificColsVisibleCommand: ICommand<ISetSpecificColsVisibleComm
const undoRedoService = accessor.get(IUndoRedoService);
undoRedoService.pushUndoRedo({
unitID: workbookId,
- async undo() {
- return sequenceExecute(
- [
- { id: SetColHiddenMutation.id, params: undoMutationParams },
- { id: SetSelectionsOperation.id, params: undoSetSelectionsOperationParams },
- ],
- commandService
- ).result;
- },
-
- async redo() {
- return sequenceExecute(
- [
- { id: SetColVisibleMutation.id, params: redoMutationParams },
- { id: SetSelectionsOperation.id, params: setSelectionOperationParams },
- ],
- commandService
- ).result;
- },
+ undoMutations: [
+ { id: SetColHiddenMutation.id, params: undoMutationParams },
+ { id: SetSelectionsOperation.id, params: undoSetSelectionsOperationParams },
+ ],
+ redoMutations: [
+ { id: SetColVisibleMutation.id, params: redoMutationParams },
+ { id: SetSelectionsOperation.id, params: setSelectionOperationParams },
+ ],
});
return true;
@@ -197,24 +186,14 @@ export const SetColHiddenCommand: ICommand = {
const undoMutationParams = SetColHiddenUndoMutationFactory(accessor, redoMutationParams);
undoRedoService.pushUndoRedo({
unitID: workbookId,
- async undo() {
- return sequenceExecute(
- [
- { id: SetColVisibleMutation.id, params: undoMutationParams },
- { id: SetSelectionsOperation.id, params: undoSetSelectionsOperationParams },
- ],
- commandService
- ).result;
- },
- async redo() {
- return sequenceExecute(
- [
- { id: SetColHiddenMutation.id, params: redoMutationParams },
- { id: SetSelectionsOperation.id, params: setSelectionOperationParams },
- ],
- commandService
- ).result;
- },
+ undoMutations: [
+ { id: SetColVisibleMutation.id, params: undoMutationParams },
+ { id: SetSelectionsOperation.id, params: undoSetSelectionsOperationParams },
+ ],
+ redoMutations: [
+ { id: SetColHiddenMutation.id, params: redoMutationParams },
+ { id: SetSelectionsOperation.id, params: setSelectionOperationParams },
+ ],
});
return true;
}
diff --git a/packages/base-sheets/src/commands/commands/set-frozen-cancel.command.ts b/packages/base-sheets/src/commands/commands/set-frozen-cancel.command.ts
index 4c33f77103..667dde26e1 100644
--- a/packages/base-sheets/src/commands/commands/set-frozen-cancel.command.ts
+++ b/packages/base-sheets/src/commands/commands/set-frozen-cancel.command.ts
@@ -42,18 +42,8 @@ export const SetFrozenCancelCommand: ICommand = {
if (result) {
undoRedoService.pushUndoRedo({
unitID: workbookId,
- undo() {
- return commandService.syncExecuteCommand(
- SetFrozenMutation.id,
- undoMutationParams
- ) as Promise<boolean>;
- },
- redo() {
- return commandService.syncExecuteCommand(
- SetFrozenMutation.id,
- redoMutationParams
- ) as Promise<boolean>;
- },
+ undoMutations: [{ id: SetFrozenMutation.id, params: undoMutationParams }],
+ redoMutations: [{ id: SetFrozenMutation.id, params: redoMutationParams }],
});
return true;
}
diff --git a/packages/base-sheets/src/commands/commands/set-frozen.command.ts b/packages/base-sheets/src/commands/commands/set-frozen.command.ts
index 0a012767c8..c910fa1d0e 100644
--- a/packages/base-sheets/src/commands/commands/set-frozen.command.ts
+++ b/packages/base-sheets/src/commands/commands/set-frozen.command.ts
@@ -46,12 +46,8 @@ export const SetFrozenCommand: ICommand = {
if (result) {
undoRedoService.pushUndoRedo({
unitID: workbookId,
- undo() {
- return commandService.syncExecuteCommand(SetFrozenMutation.id, undoMutationParams);
- },
- redo() {
- return commandService.syncExecuteCommand(SetFrozenMutation.id, redoMutationParams);
- },
+ undoMutations: [{ id: SetFrozenMutation.id, params: undoMutationParams }],
+ redoMutations: [{ id: SetFrozenMutation.id, params: redoMutationParams }],
});
return true;
}
diff --git a/packages/base-sheets/src/commands/commands/set-hide-gridlines.command.ts b/packages/base-sheets/src/commands/commands/set-hide-gridlines.command.ts
index df0e455e5a..304bff35ba 100644
--- a/packages/base-sheets/src/commands/commands/set-hide-gridlines.command.ts
+++ b/packages/base-sheets/src/commands/commands/set-hide-gridlines.command.ts
@@ -60,15 +60,8 @@ export const SetHideGridlinesCommand: ICommand = {
if (result) {
undoRedoService.pushUndoRedo({
unitID: workbookId,
- undo() {
- return commandService.syncExecuteCommand(SetHideGridlinesMutation.id, undoMutationParams);
- },
- redo() {
- return commandService.syncExecuteCommand(
- SetHideGridlinesMutation.id,
- setHideGridlinesMutationParams
- );
- },
+ undoMutations: [{ id: SetHideGridlinesMutation.id, params: undoMutationParams }],
+ redoMutations: [{ id: SetHideGridlinesMutation.id, params: setHideGridlinesMutationParams }],
});
return true;
}
diff --git a/packages/base-sheets/src/commands/commands/set-range-formatted-value.command.ts b/packages/base-sheets/src/commands/commands/set-range-formatted-value.command.ts
index ca2a762d70..91598b53c5 100644
--- a/packages/base-sheets/src/commands/commands/set-range-formatted-value.command.ts
+++ b/packages/base-sheets/src/commands/commands/set-range-formatted-value.command.ts
@@ -90,21 +90,13 @@ export const SetRangeFormattedValueCommand: ICommand = {
);
if (result) {
undoRedoService.pushUndoRedo({
- // 如果有多个 mutation 构成一个封装项目,那么要封装在同一个 undo redo element 里面
- // 通过勾子可以 hook 外部 controller 的代码来增加新的 action
unitID: workbookId,
- undo() {
- return commandService.executeCommand(
- SetRangeFormattedValueMutation.id,
- undoSetRangeFormattedValueMutationParams
- );
- },
- redo() {
- return commandService.executeCommand(
- SetRangeFormattedValueMutation.id,
- setRangeFormattedValueMutationParams
- );
- },
+ undoMutations: [
+ { id: SetRangeFormattedValueMutation.id, params: undoSetRangeFormattedValueMutationParams },
+ ],
+ redoMutations: [
+ { id: SetRangeFormattedValueMutation.id, params: setRangeFormattedValueMutationParams },
+ ],
});
return true;
diff --git a/packages/base-sheets/src/commands/commands/set-range-values.command.ts b/packages/base-sheets/src/commands/commands/set-range-values.command.ts
index da9bcbd4f7..cdf1cdd171 100644
--- a/packages/base-sheets/src/commands/commands/set-range-values.command.ts
+++ b/packages/base-sheets/src/commands/commands/set-range-values.command.ts
@@ -112,16 +112,8 @@ export const SetRangeValuesCommand: ICommand = {
if (setValueMutationResult && result.result) {
undoRedoService.pushUndoRedo({
unitID: workbookId,
- undo: async () =>
- sequenceExecute(
- [{ id: SetRangeValuesMutation.id, params: undoSetRangeValuesMutationParams }, ...undos],
- commandService
- ).result,
- redo: async () =>
- sequenceExecute(
- [{ id: SetRangeValuesMutation.id, params: setRangeValuesMutationParams }, ...redos],
- commandService
- ).result,
+ undoMutations: [{ id: SetRangeValuesMutation.id, params: undoSetRangeValuesMutationParams }, ...undos],
+ redoMutations: [{ id: SetRangeValuesMutation.id, params: setRangeValuesMutationParams }, ...redos],
});
return true;
diff --git a/packages/base-sheets/src/commands/commands/set-row-visible.command.ts b/packages/base-sheets/src/commands/commands/set-row-visible.command.ts
index e3c908b60b..35a367c691 100644
--- a/packages/base-sheets/src/commands/commands/set-row-visible.command.ts
+++ b/packages/base-sheets/src/commands/commands/set-row-visible.command.ts
@@ -80,24 +80,14 @@ export const SetSpecificRowsVisibleCommand: ICommand<ISetSpecificRowsVisibleComm
if (result.result) {
undoRedoService.pushUndoRedo({
unitID: workbookId,
- async undo() {
- return sequenceExecute(
- [
- { id: SetRowHiddenMutation.id, params: undoMutationParams },
- { id: SetSelectionsOperation.id, params: undoSetSelectionsOperationParams },
- ],
- commandService
- ).result;
- },
- async redo() {
- return sequenceExecute(
- [
- { id: SetRowVisibleMutation.id, params: redoMutationParams },
- { id: SetSelectionsOperation.id, params: setSelectionOperationParams },
- ],
- commandService
- ).result;
- },
+ undoMutations: [
+ { id: SetRowHiddenMutation.id, params: undoMutationParams },
+ { id: SetSelectionsOperation.id, params: undoSetSelectionsOperationParams },
+ ],
+ redoMutations: [
+ { id: SetRowVisibleMutation.id, params: redoMutationParams },
+ { id: SetSelectionsOperation.id, params: setSelectionOperationParams },
+ ],
});
return true;
@@ -200,24 +190,14 @@ export const SetRowHiddenCommand: ICommand = {
if (result.result) {
undoRedoService.pushUndoRedo({
unitID: workbookId,
- async undo() {
- return sequenceExecute(
- [
- { id: SetRowVisibleMutation.id, params: undoMutationParams },
- { id: SetSelectionsOperation.id, params: undoSetSelectionsOperationParams },
- ],
- commandService
- ).result;
- },
- async redo() {
- return sequenceExecute(
- [
- { id: SetRowHiddenMutation.id, params: redoMutationParams },
- { id: SetSelectionsOperation.id, params: setSelectionOperationParams },
- ],
- commandService
- ).result;
- },
+ undoMutations: [
+ { id: SetRowVisibleMutation.id, params: undoMutationParams },
+ { id: SetSelectionsOperation.id, params: undoSetSelectionsOperationParams },
+ ],
+ redoMutations: [
+ { id: SetRowHiddenMutation.id, params: redoMutationParams },
+ { id: SetSelectionsOperation.id, params: setSelectionOperationParams },
+ ],
});
return true;
}
diff --git a/packages/base-sheets/src/commands/commands/set-style.command.ts b/packages/base-sheets/src/commands/commands/set-style.command.ts
index f7a59d4903..da9d6ffd62 100644
--- a/packages/base-sheets/src/commands/commands/set-style.command.ts
+++ b/packages/base-sheets/src/commands/commands/set-style.command.ts
@@ -131,16 +131,8 @@ export const SetStyleCommand: ICommand<ISetStyleParams<unknown>> = {
if (setRangeValuesResult && result.result) {
undoRedoService.pushUndoRedo({
unitID: workbookId,
- undo: async () =>
- sequenceExecute(
- [{ id: SetRangeValuesMutation.id, params: undoSetRangeValuesMutationParams }, ...undos],
- commandService
- ).result,
- redo: async () =>
- sequenceExecute(
- [{ id: SetRangeValuesMutation.id, params: setRangeValuesMutationParams }, ...redos],
- commandService
- ).result,
+ undoMutations: [{ id: SetRangeValuesMutation.id, params: undoSetRangeValuesMutationParams }, ...undos],
+ redoMutations: [{ id: SetRangeValuesMutation.id, params: setRangeValuesMutationParams }, ...redos],
});
return true;
diff --git a/packages/base-sheets/src/commands/commands/set-tab-color.command.ts b/packages/base-sheets/src/commands/commands/set-tab-color.command.ts
index efb8cd701e..2f6decc320 100644
--- a/packages/base-sheets/src/commands/commands/set-tab-color.command.ts
+++ b/packages/base-sheets/src/commands/commands/set-tab-color.command.ts
@@ -44,12 +44,8 @@ export const SetTabColorCommand: ICommand = {
if (result) {
undoRedoService.pushUndoRedo({
unitID: workbookId,
- undo() {
- return commandService.syncExecuteCommand(SetTabColorMutation.id, undoMutationParams);
- },
- redo() {
- return commandService.syncExecuteCommand(SetTabColorMutation.id, setTabColorMutationParams);
- },
+ undoMutations: [{ id: SetTabColorMutation.id, params: undoMutationParams }],
+ redoMutations: [{ id: SetTabColorMutation.id, params: setTabColorMutationParams }],
});
return true;
}
diff --git a/packages/base-sheets/src/commands/commands/set-worksheet-activate.command.ts b/packages/base-sheets/src/commands/commands/set-worksheet-activate.command.ts
index a23f7298b3..4cb778a600 100644
--- a/packages/base-sheets/src/commands/commands/set-worksheet-activate.command.ts
+++ b/packages/base-sheets/src/commands/commands/set-worksheet-activate.command.ts
@@ -36,22 +36,7 @@ export const SetWorksheetActivateCommand: ICommand = {
workbookId,
worksheetId,
};
- // const undoMutationParams = SetWorksheetUnActivateMutationFactory(accessor, redoMutationParams);
- const result = commandService.syncExecuteCommand(SetWorksheetActivateMutation.id, redoMutationParams);
-
- // no need
- // if (result) {
- // undoRedoService.pushUndoRedo({
- // unitID: workbookId,
- // undo() {
- // return commandService.syncExecuteCommand(SetWorksheetActivateMutation.id, undoMutationParams);
- // },
- // redo() {
- // return commandService.syncExecuteCommand(SetWorksheetActivateMutation.id, redoMutationParams);
- // },
- // });
- // return true;
- // }
- return true;
+
+ return commandService.syncExecuteCommand(SetWorksheetActivateMutation.id, redoMutationParams);
},
};
diff --git a/packages/base-sheets/src/commands/commands/set-worksheet-col-width.command.ts b/packages/base-sheets/src/commands/commands/set-worksheet-col-width.command.ts
index 6b59a3915e..f044bddbc0 100644
--- a/packages/base-sheets/src/commands/commands/set-worksheet-col-width.command.ts
+++ b/packages/base-sheets/src/commands/commands/set-worksheet-col-width.command.ts
@@ -99,16 +99,8 @@ export const DeltaColumnWidthCommand: ICommand<IDeltaColumnWidthCommandParams> =
if (setColWidthResult && result.result) {
undoRedoService.pushUndoRedo({
unitID: workbookId,
- undo: async () =>
- sequenceExecute(
- [{ id: SetWorksheetColWidthMutation.id, params: undoMutationParams }, ...undos],
- commandService
- ).result,
- redo: async () =>
- sequenceExecute(
- [{ id: SetWorksheetColWidthMutation.id, params: redoMutationParams }, ...redos],
- commandService
- ).result,
+ undoMutations: [{ id: SetWorksheetColWidthMutation.id, params: undoMutationParams }, ...undos],
+ redoMutations: [{ id: SetWorksheetColWidthMutation.id, params: redoMutationParams }, ...redos],
});
return true;
@@ -164,16 +156,8 @@ export const SetColWidthCommand: ICommand = {
if (setColWidthResult && result.result) {
undoRedoService.pushUndoRedo({
unitID: workbookId,
- undo: async () =>
- sequenceExecute(
- [{ id: SetWorksheetColWidthMutation.id, params: undoMutationParams }, ...undos],
- commandService
- ).result,
- redo: async () =>
- sequenceExecute(
- [{ id: SetWorksheetColWidthMutation.id, params: redoMutationParams }, ...redos],
- commandService
- ).result,
+ undoMutations: [{ id: SetWorksheetColWidthMutation.id, params: undoMutationParams }, ...undos],
+ redoMutations: [{ id: SetWorksheetColWidthMutation.id, params: redoMutationParams }, ...redos],
});
return true;
diff --git a/packages/base-sheets/src/commands/commands/set-worksheet-hide.command.ts b/packages/base-sheets/src/commands/commands/set-worksheet-hide.command.ts
index a75b951d79..5ba2c117fd 100644
--- a/packages/base-sheets/src/commands/commands/set-worksheet-hide.command.ts
+++ b/packages/base-sheets/src/commands/commands/set-worksheet-hide.command.ts
@@ -76,30 +76,14 @@ export const SetWorksheetHideCommand: ICommand = {
if (result && activeResult) {
undoRedoService.pushUndoRedo({
unitID: workbookId,
- undo() {
- return (
- commandService.executeCommand(
- SetWorksheetActivateMutation.id,
- unActiveMutationParams
- ) as Promise<boolean>
- ).then((res) => {
- if (res)
- return commandService.syncExecuteCommand(SetWorksheetHideMutation.id, undoMutationParams);
- return false;
- });
- },
- redo() {
- return (
- commandService.executeCommand(
- SetWorksheetActivateMutation.id,
- activeSheetMutationParams
- ) as Promise<boolean>
- ).then((res) => {
- if (res)
- return commandService.syncExecuteCommand(SetWorksheetHideMutation.id, redoMutationParams);
- return false;
- });
- },
+ undoMutations: [
+ { id: SetWorksheetActivateMutation.id, params: unActiveMutationParams },
+ { id: SetWorksheetHideMutation.id, params: undoMutationParams },
+ ],
+ redoMutations: [
+ { id: SetWorksheetActivateMutation.id, params: activeSheetMutationParams },
+ { id: SetWorksheetHideMutation.id, params: redoMutationParams },
+ ],
});
return true;
}
diff --git a/packages/base-sheets/src/commands/commands/set-worksheet-name.command.ts b/packages/base-sheets/src/commands/commands/set-worksheet-name.command.ts
index bee8ada443..f59a577b71 100644
--- a/packages/base-sheets/src/commands/commands/set-worksheet-name.command.ts
+++ b/packages/base-sheets/src/commands/commands/set-worksheet-name.command.ts
@@ -43,12 +43,8 @@ export const SetWorksheetNameCommand: ICommand = {
if (result) {
undoRedoService.pushUndoRedo({
unitID: workbookId,
- undo() {
- return commandService.syncExecuteCommand(SetWorksheetNameMutation.id, undoMutationParams);
- },
- redo() {
- return commandService.syncExecuteCommand(SetWorksheetNameMutation.id, redoMutationParams);
- },
+ undoMutations: [{ id: SetWorksheetNameMutation.id, params: undoMutationParams }],
+ redoMutations: [{ id: SetWorksheetNameMutation.id, params: redoMutationParams }],
});
return true;
diff --git a/packages/base-sheets/src/commands/commands/set-worksheet-order.command.ts b/packages/base-sheets/src/commands/commands/set-worksheet-order.command.ts
index af612f6827..12f2349ca0 100644
--- a/packages/base-sheets/src/commands/commands/set-worksheet-order.command.ts
+++ b/packages/base-sheets/src/commands/commands/set-worksheet-order.command.ts
@@ -43,15 +43,8 @@ export const SetWorksheetOrderCommand: ICommand = {
if (result) {
undoRedoService.pushUndoRedo({
unitID: workbookId,
- undo() {
- return commandService.syncExecuteCommand(SetWorksheetOrderMutation.id, undoMutationParams);
- },
- redo() {
- return commandService.syncExecuteCommand(
- SetWorksheetOrderMutation.id,
- setWorksheetOrderMutationParams
- );
- },
+ undoMutations: [{ id: SetWorksheetOrderMutation.id, params: undoMutationParams }],
+ redoMutations: [{ id: SetWorksheetOrderMutation.id, params: setWorksheetOrderMutationParams }],
});
return true;
}
diff --git a/packages/base-sheets/src/commands/commands/set-worksheet-right-to-left.command.ts b/packages/base-sheets/src/commands/commands/set-worksheet-right-to-left.command.ts
index ab09668b7c..151a167931 100644
--- a/packages/base-sheets/src/commands/commands/set-worksheet-right-to-left.command.ts
+++ b/packages/base-sheets/src/commands/commands/set-worksheet-right-to-left.command.ts
@@ -66,15 +66,10 @@ export const SetWorksheetRightToLeftCommand: ICommand = {
if (result) {
undoRedoService.pushUndoRedo({
unitID: workbookId,
- undo() {
- return commandService.syncExecuteCommand(SetWorksheetRightToLeftMutation.id, undoMutationParams);
- },
- redo() {
- return commandService.syncExecuteCommand(
- SetWorksheetRightToLeftMutation.id,
- setWorksheetRightToLeftMutationParams
- );
- },
+ undoMutations: [{ id: SetWorksheetRightToLeftMutation.id, params: undoMutationParams }],
+ redoMutations: [
+ { id: SetWorksheetRightToLeftMutation.id, params: setWorksheetRightToLeftMutationParams },
+ ],
});
return true;
}
diff --git a/packages/base-sheets/src/commands/commands/set-worksheet-row-height.command.ts b/packages/base-sheets/src/commands/commands/set-worksheet-row-height.command.ts
index 9bf2a7647b..70087db375 100644
--- a/packages/base-sheets/src/commands/commands/set-worksheet-row-height.command.ts
+++ b/packages/base-sheets/src/commands/commands/set-worksheet-row-height.command.ts
@@ -114,38 +114,26 @@ export const DeltaRowHeightCommand: ICommand = {
if (result.result) {
undoRedoService.pushUndoRedo({
unitID: workbookId,
- undo: async () =>
- (
- await sequenceExecute(
- [
- {
- id: SetWorksheetRowHeightMutation.id,
- params: undoMutationParams,
- },
- {
- id: SetWorksheetRowIsAutoHeightMutation.id,
- params: undoSetIsAutoHeightParams,
- },
- ],
- commandService
- )
- ).result,
- redo: async () =>
- (
- await sequenceExecute(
- [
- {
- id: SetWorksheetRowHeightMutation.id,
- params: redoMutationParams,
- },
- {
- id: SetWorksheetRowIsAutoHeightMutation.id,
- params: redoSetIsAutoHeightParams,
- },
- ],
- commandService
- )
- ).result,
+ undoMutations: [
+ {
+ id: SetWorksheetRowHeightMutation.id,
+ params: undoMutationParams,
+ },
+ {
+ id: SetWorksheetRowIsAutoHeightMutation.id,
+ params: undoSetIsAutoHeightParams,
+ },
+ ],
+ redoMutations: [
+ {
+ id: SetWorksheetRowHeightMutation.id,
+ params: redoMutationParams,
+ },
+ {
+ id: SetWorksheetRowIsAutoHeightMutation.id,
+ params: redoSetIsAutoHeightParams,
+ },
+ ],
});
return true;
}
@@ -214,38 +202,26 @@ export const SetRowHeightCommand: ICommand = {
if (result.result) {
undoRedoService.pushUndoRedo({
unitID: workbookId,
- undo: async () =>
- (
- await sequenceExecute(
- [
- {
- id: SetWorksheetRowHeightMutation.id,
- params: undoMutationParams,
- },
- {
- id: SetWorksheetRowIsAutoHeightMutation.id,
- params: undoSetIsAutoHeightParams,
- },
- ],
- commandService
- )
- ).result,
- redo: async () =>
- (
- await sequenceExecute(
- [
- {
- id: SetWorksheetRowHeightMutation.id,
- params: redoMutationParams,
- },
- {
- id: SetWorksheetRowIsAutoHeightMutation.id,
- params: redoSetIsAutoHeightParams,
- },
- ],
- commandService
- )
- ).result,
+ undoMutations: [
+ {
+ id: SetWorksheetRowHeightMutation.id,
+ params: undoMutationParams,
+ },
+ {
+ id: SetWorksheetRowIsAutoHeightMutation.id,
+ params: undoSetIsAutoHeightParams,
+ },
+ ],
+ redoMutations: [
+ {
+ id: SetWorksheetRowHeightMutation.id,
+ params: redoMutationParams,
+ },
+ {
+ id: SetWorksheetRowIsAutoHeightMutation.id,
+ params: redoSetIsAutoHeightParams,
+ },
+ ],
});
return true;
}
@@ -297,20 +273,8 @@ export const SetWorksheetRowIsAutoHeightCommand: ICommand = {
if (setIsAutoHeightResult && result.result) {
undoRedoService.pushUndoRedo({
unitID: workbookId,
- undo: async () =>
- (
- await sequenceExecute(
- [{ id: SetWorksheetRowIsAutoHeightMutation.id, params: undoMutationParams }, ...undos],
- commandService
- )
- ).result,
- redo: async () =>
- (
- await sequenceExecute(
- [{ id: SetWorksheetRowIsAutoHeightMutation.id, params: redoMutationParams }, ...redos],
- commandService
- )
- ).result,
+ undoMutations: [{ id: SetWorksheetRowIsAutoHeightMutation.id, params: undoMutationParams }, ...undos],
+ redoMutations: [{ id: SetWorksheetRowIsAutoHeightMutation.id, params: redoMutationParams }, ...redos],
});
return true;
diff --git a/packages/base-sheets/src/commands/commands/set-worksheet-show.command.ts b/packages/base-sheets/src/commands/commands/set-worksheet-show.command.ts
index 77247d584f..cef306a3fd 100644
--- a/packages/base-sheets/src/commands/commands/set-worksheet-show.command.ts
+++ b/packages/base-sheets/src/commands/commands/set-worksheet-show.command.ts
@@ -74,30 +74,14 @@ export const SetWorksheetShowCommand: ICommand = {
if (result && activeResult) {
undoRedoService.pushUndoRedo({
unitID: workbookId,
- undo() {
- return (
- commandService.executeCommand(
- SetWorksheetActivateMutation.id,
- unActiveMutationParams
- ) as Promise<boolean>
- ).then((res) => {
- if (res)
- return commandService.syncExecuteCommand(SetWorksheetHideMutation.id, undoMutationParams);
- return false;
- });
- },
- redo() {
- return (
- commandService.executeCommand(
- SetWorksheetActivateMutation.id,
- activeSheetMutationParams
- ) as Promise<boolean>
- ).then((res) => {
- if (res)
- return commandService.syncExecuteCommand(SetWorksheetHideMutation.id, redoMutationParams);
- return false;
- });
- },
+ undoMutations: [
+ { id: SetWorksheetHideMutation.id, params: undoMutationParams },
+ { id: SetWorksheetActivateMutation.id, params: unActiveMutationParams },
+ ],
+ redoMutations: [
+ { id: SetWorksheetActivateMutation.id, params: activeSheetMutationParams },
+ { id: SetWorksheetHideMutation.id, params: redoMutationParams },
+ ],
});
return true;
}
diff --git a/packages/base-sheets/src/commands/commands/trim-whitespace.command.ts b/packages/base-sheets/src/commands/commands/trim-whitespace.command.ts
index 0c760b11aa..adc13c27d1 100644
--- a/packages/base-sheets/src/commands/commands/trim-whitespace.command.ts
+++ b/packages/base-sheets/src/commands/commands/trim-whitespace.command.ts
@@ -72,21 +72,13 @@ export const TrimWhitespaceCommand: ICommand = {
);
if (result) {
undoRedoService.pushUndoRedo({
- // 如果有多个 mutation 构成一个封装项目,那么要封装在同一个 undo redo element 里面
- // 通过勾子可以 hook 外部 controller 的代码来增加新的 action
unitID: workbookId,
- undo() {
- return commandService.executeCommand(
- SetRangeFormattedValueMutation.id,
- undoSetRangeFormattedValueMutationParams
- );
- },
- redo() {
- return commandService.executeCommand(
- SetRangeFormattedValueMutation.id,
- setRangeFormattedValueMutationParams
- );
- },
+ undoMutations: [
+ { id: SetRangeFormattedValueMutation.id, params: undoSetRangeFormattedValueMutationParams },
+ ],
+ redoMutations: [
+ { id: SetRangeFormattedValueMutation.id, params: setRangeFormattedValueMutationParams },
+ ],
});
return true;
diff --git a/packages/core/src/services/undoredo/undoredo.service.ts b/packages/core/src/services/undoredo/undoredo.service.ts
index 803467c8a4..43db9a015a 100644
--- a/packages/core/src/services/undoredo/undoredo.service.ts
+++ b/packages/core/src/services/undoredo/undoredo.service.ts
@@ -2,7 +2,7 @@ import { createIdentifier, IAccessor, IDisposable } from '@wendellhu/redi';
import { BehaviorSubject, Observable } from 'rxjs';
import { Disposable, toDisposable } from '../../Shared/lifecycle';
-import { CommandType, ICommand, ICommandInfo, ICommandService } from '../command/command.service';
+import { CommandType, ICommand, ICommandInfo, ICommandService, sequenceExecute } from '../command/command.service';
import { IUniverInstanceService } from '../instance/instance.service';
// TODO: an undo redo element may be merge-able to another undo redo element
@@ -11,13 +11,11 @@ export interface IUndoRedoItem {
/** unitID maps to unitId for UniverSheet / UniverDoc / UniverSlide */
unitID: string;
- undoMutations?: ICommandInfo[];
- redoMutations?: ICommandInfo[];
+ undoMutations: ICommandInfo[];
+ redoMutations: ICommandInfo[];
- /** @deprecated, push to `undoMutations` instead. */
- undo(): Promise<boolean> | boolean;
- /** @deprecated, push to `redoMutations` instead. */
- redo(): Promise<boolean> | boolean;
+ undo?(mutations: ICommandInfo[]): Promise<boolean> | boolean;
+ redo?(mutations: ICommandInfo[]): Promise<boolean> | boolean;
}
export interface IUndoRedoService {
@@ -220,7 +218,10 @@ export const UndoCommand = new (class extends MultiImplementationCommand impleme
return false;
}
- const result = await element.undo();
+ const commandService = accessor.get(ICommandService);
+ const result = element.undo
+ ? await element.undo(element.undoMutations)
+ : sequenceExecute(element.undoMutations, commandService);
if (result) {
undoRedoService.popUndoToRedo();
@@ -243,7 +244,10 @@ export const RedoCommand = new (class extends MultiImplementationCommand impleme
return false;
}
- const result = await element.redo();
+ const commandService = accessor.get(ICommandService);
+ const result = element.redo
+ ? await element.redo(element.redoMutations)
+ : sequenceExecute(element.redoMutations, commandService);
if (result) {
undoRedoService.popRedoToUndo();
diff --git a/packages/ui-plugin-sheets/src/commands/commands/set-frozen.command.ts b/packages/ui-plugin-sheets/src/commands/commands/set-frozen.command.ts
index 7574fe3ee8..d98995cd2c 100644
--- a/packages/ui-plugin-sheets/src/commands/commands/set-frozen.command.ts
+++ b/packages/ui-plugin-sheets/src/commands/commands/set-frozen.command.ts
@@ -77,12 +77,8 @@ export const SetSelectionFrozenCommand: ICommand = {
if (result) {
undoRedoService.pushUndoRedo({
unitID: workbookId,
- undo() {
- return commandService.syncExecuteCommand(SetFrozenMutation.id, undoMutationParams);
- },
- redo() {
- return commandService.syncExecuteCommand(SetFrozenMutation.id, redoMutationParams);
- },
+ undoMutations: [{ id: SetFrozenMutation.id, params: undoMutationParams }],
+ redoMutations: [{ id: SetFrozenMutation.id, params: redoMutationParams }],
});
return true;
}