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(drawing): fix sheets drawing transform when insert rows, columns, etc. (#5833)

wpxp123456cf35a85815ac
diff --git a/packages/sheets-drawing-ui/src/controllers/sheet-drawing-transform-affected.controller.ts b/packages/sheets-drawing-ui/src/controllers/sheet-drawing-transform-affected.controller.ts
index 86251406bb..452a4b7472 100644
--- a/packages/sheets-drawing-ui/src/controllers/sheet-drawing-transform-affected.controller.ts
+++ b/packages/sheets-drawing-ui/src/controllers/sheet-drawing-transform-affected.controller.ts
@@ -90,8 +90,8 @@ export class SheetDrawingTransformAffectedController extends Disposable implemen
private _sheetInterceptorListener() {
this.disposeWithMe(
- this._sheetInterceptorService.interceptCommand({
-
+ this._sheetInterceptorService.interceptAfterCommand({
+ /* eslint-disable-next-line complexity */
getMutations: (commandInfo) => {
if (!UPDATE_COMMANDS.includes(commandInfo.id)) {
return { redos: [], undos: [] };
diff --git a/packages/sheets/src/commands/commands/delete-range-move-left.command.ts b/packages/sheets/src/commands/commands/delete-range-move-left.command.ts
index 1bea01d32e..990de9d896 100644
--- a/packages/sheets/src/commands/commands/delete-range-move-left.command.ts
+++ b/packages/sheets/src/commands/commands/delete-range-move-left.command.ts
@@ -85,6 +85,14 @@ export const DeleteRangeMoveLeftCommand: ICommand = {
const result = sequenceExecute(redos, commandService).result;
if (result) {
+ const afterInterceptors = sheetInterceptorService.afterCommandExecute({
+ id: DeleteRangeMoveLeftCommand.id,
+ params: { range } as IDeleteRangeMoveLeftCommandParams,
+ });
+ sequenceExecute(afterInterceptors.redos, commandService);
+ undos.push(...afterInterceptors.undos);
+ redos.push(...afterInterceptors.redos);
+
undoRedoService.pushUndoRedo({
unitID: unitId,
undoMutations: undos.reverse(),
diff --git a/packages/sheets/src/commands/commands/delete-range-move-up.command.ts b/packages/sheets/src/commands/commands/delete-range-move-up.command.ts
index 0f4f73795d..e34f40a525 100644
--- a/packages/sheets/src/commands/commands/delete-range-move-up.command.ts
+++ b/packages/sheets/src/commands/commands/delete-range-move-up.command.ts
@@ -84,6 +84,14 @@ export const DeleteRangeMoveUpCommand: ICommand = {
const result = sequenceExecute(redos, commandService).result;
if (result) {
+ const afterInterceptors = sheetInterceptorService.afterCommandExecute({
+ id: DeleteRangeMoveUpCommand.id,
+ params: { range } as IDeleteRangeMoveUpCommandParams,
+ });
+ sequenceExecute(afterInterceptors.redos, commandService);
+ undos.push(...afterInterceptors.undos);
+ redos.push(...afterInterceptors.redos);
+
undoRedoService.pushUndoRedo({
unitID: unitId,
undoMutations: undos.reverse(),
diff --git a/packages/sheets/src/commands/commands/insert-range-move-down.command.ts b/packages/sheets/src/commands/commands/insert-range-move-down.command.ts
index 3e19caff4b..c51c0c8e69 100644
--- a/packages/sheets/src/commands/commands/insert-range-move-down.command.ts
+++ b/packages/sheets/src/commands/commands/insert-range-move-down.command.ts
@@ -163,6 +163,14 @@ export const InsertRangeMoveDownCommand: ICommand = {
// execute do mutations and add undo mutations to undo stack if completed
const result = sequenceExecute(redoMutations, commandService);
if (result) {
+ const afterInterceptors = sheetInterceptorService.afterCommandExecute({
+ id: InsertRangeMoveDownCommand.id,
+ params: { range } as InsertRangeMoveDownCommandParams,
+ });
+ sequenceExecute(afterInterceptors.redos, commandService);
+ undoMutations.push(...afterInterceptors.undos);
+ redoMutations.push(...afterInterceptors.redos);
+
undoRedoService.pushUndoRedo({
unitID: unitId,
undoMutations: undoMutations.reverse(),
diff --git a/packages/sheets/src/commands/commands/insert-range-move-right.command.ts b/packages/sheets/src/commands/commands/insert-range-move-right.command.ts
index b5cbd2686e..6ba7cf7b7b 100644
--- a/packages/sheets/src/commands/commands/insert-range-move-right.command.ts
+++ b/packages/sheets/src/commands/commands/insert-range-move-right.command.ts
@@ -163,6 +163,14 @@ export const InsertRangeMoveRightCommand: ICommand = {
// execute do mutations and add undo mutations to undo stack if completed
const result = sequenceExecute(redoMutations, commandService);
if (result.result) {
+ const afterInterceptors = sheetInterceptorService.afterCommandExecute({
+ id: InsertRangeMoveRightCommand.id,
+ params: { range } as InsertRangeMoveRightCommandParams,
+ });
+ sequenceExecute(afterInterceptors.redos, commandService);
+ undoMutations.push(...afterInterceptors.undos);
+ redoMutations.push(...afterInterceptors.redos);
+
undoRedoService.pushUndoRedo({
unitID: unitId,
undoMutations: undoMutations.reverse(),
diff --git a/packages/sheets/src/commands/commands/insert-row-col.command.ts b/packages/sheets/src/commands/commands/insert-row-col.command.ts
index 92b1af2709..1791a276b0 100644
--- a/packages/sheets/src/commands/commands/insert-row-col.command.ts
+++ b/packages/sheets/src/commands/commands/insert-row-col.command.ts
@@ -159,6 +159,14 @@ export const InsertRowByRangeCommand: ICommand = {
const result = sequenceExecute(redos, commandService);
if (result.result) {
+ const afterInterceptors = sheetInterceptorService.afterCommandExecute({
+ id: InsertRowCommand.id,
+ params,
+ });
+ sequenceExecute(afterInterceptors.redos, commandService);
+ redos.push(...afterInterceptors.redos);
+ undos.push(...afterInterceptors.undos);
+
undoRedoService.pushUndoRedo({
unitID: params.unitId,
undoMutations: undos,
@@ -462,11 +470,20 @@ export const InsertColByRangeCommand: ICommand<IInsertColCommandParams> = {
const result = sequenceExecute(redos, commandService);
if (result.result) {
+ const afterInterceptors = sheetInterceptorService.afterCommandExecute({
+ id: InsertColCommand.id,
+ params,
+ });
+ sequenceExecute(afterInterceptors.redos, commandService);
+ redos.push(...afterInterceptors.redos);
+ undos.push(...afterInterceptors.undos);
+
undoRedoService.pushUndoRedo({
unitID: params.unitId,
undoMutations: undos.filter(Boolean),
redoMutations: redos.filter(Boolean),
});
+
return true;
}
diff --git a/packages/sheets/src/commands/commands/move-range.command.ts b/packages/sheets/src/commands/commands/move-range.command.ts
index cc247a5ebc..a86df54574 100644
--- a/packages/sheets/src/commands/commands/move-range.command.ts
+++ b/packages/sheets/src/commands/commands/move-range.command.ts
@@ -114,18 +114,18 @@ export const MoveRangeCommand: ICommand = {
const result = sequenceExecute(redos, commandService).result;
- const { undos: autoHeightUndos, redos: autoHeightRedos } = sheetInterceptorService.generateMutationsOfAutoHeight({
- unitId,
- subUnitId,
- ranges: [params.fromRange, params.toRange],
- });
+ if (result) {
+ const { undos: autoHeightUndos, redos: autoHeightRedos } = sheetInterceptorService.generateMutationsOfAutoHeight({
+ unitId,
+ subUnitId,
+ ranges: [params.fromRange, params.toRange],
+ });
- const afterInterceptors = sheetInterceptorService.afterCommandExecute({
- id: MoveRangeCommand.id,
- params,
- });
+ const afterInterceptors = sheetInterceptorService.afterCommandExecute({
+ id: MoveRangeCommand.id,
+ params,
+ });
- if (result) {
sequenceExecute([...afterInterceptors.redos, ...autoHeightRedos], commandService);
undoRedoService.pushUndoRedo({
unitID: unitId,
diff --git a/packages/sheets/src/commands/commands/move-rows-cols.command.ts b/packages/sheets/src/commands/commands/move-rows-cols.command.ts
index a7657551cc..90cae37d6e 100644
--- a/packages/sheets/src/commands/commands/move-rows-cols.command.ts
+++ b/packages/sheets/src/commands/commands/move-rows-cols.command.ts
@@ -187,6 +187,14 @@ export const MoveRowsCommand: ICommand<IMoveRowsCommandParams> = {
const result = sequenceExecute(redos, commandService);
if (result.result) {
+ const afterInterceptors = sheetInterceptorService.afterCommandExecute({
+ id: MoveRowsCommand.id,
+ params,
+ });
+ sequenceExecute(afterInterceptors.redos, commandService);
+ redos.push(...afterInterceptors.redos);
+ undos.push(...afterInterceptors.undos);
+
const undoRedoService = accessor.get(IUndoRedoService);
undoRedoService.pushUndoRedo({
unitID: unitId,
@@ -328,6 +336,14 @@ export const MoveColsCommand: ICommand<IMoveColsCommandParams> = {
const result = sequenceExecute(redos, commandService);
if (result.result) {
+ const afterInterceptors = sheetInterceptorService.afterCommandExecute({
+ id: MoveColsCommand.id,
+ params,
+ });
+ sequenceExecute(afterInterceptors.redos, commandService);
+ redos.push(...afterInterceptors.redos);
+ undos.push(...afterInterceptors.undos);
+
const undoRedoService = accessor.get(IUndoRedoService);
undoRedoService.pushUndoRedo({
unitID: unitId,
diff --git a/packages/sheets/src/commands/commands/remove-row-col.command.ts b/packages/sheets/src/commands/commands/remove-row-col.command.ts
index 2b3ffac93c..f7defbb169 100644
--- a/packages/sheets/src/commands/commands/remove-row-col.command.ts
+++ b/packages/sheets/src/commands/commands/remove-row-col.command.ts
@@ -131,6 +131,12 @@ export const RemoveRowByRangeCommand: ICommand<IRemoveRowByRangeCommandParams> =
);
if (result.result) {
+ const afterInterceptors = sheetInterceptorService.afterCommandExecute({
+ id: RemoveRowCommandId,
+ params: { range } as IRemoveRowColCommandParams,
+ });
+ sequenceExecute(afterInterceptors.redos, commandService);
+
const undoRedoService = accessor.get(IUndoRedoService);
undoRedoService.pushUndoRedo({
unitID: unitId,
@@ -138,11 +144,13 @@ export const RemoveRowByRangeCommand: ICommand<IRemoveRowByRangeCommandParams> =
...(intercepted.preUndos ?? []),
...undoMutations,
...intercepted.undos,
+ ...afterInterceptors.undos,
],
redoMutations: [
...(intercepted.preRedos ?? []),
...redoMutations,
...intercepted.redos,
+ ...afterInterceptors.redos,
],
});
return true;
@@ -243,6 +251,12 @@ export const RemoveColByRangeCommand: ICommand<IRemoveColByRangeCommandParams> =
);
if (result.result) {
+ const afterInterceptors = sheetInterceptorService.afterCommandExecute({
+ id: RemoveColCommandId,
+ params: { range } as IRemoveRowColCommandParams,
+ });
+ sequenceExecute(afterInterceptors.redos, commandService);
+
const undoRedoService = accessor.get(IUndoRedoService);
undoRedoService.pushUndoRedo({
unitID: unitId,
@@ -251,11 +265,13 @@ export const RemoveColByRangeCommand: ICommand<IRemoveColByRangeCommandParams> =
{ id: InsertColMutation.id, params: undoRemoveColParams },
{ id: SetRangeValuesMutation.id, params: undoSetRangeValuesParams },
...intercepted.undos,
+ ...afterInterceptors.undos,
],
redoMutations: [
...(intercepted.preRedos ?? []),
{ id: RemoveColMutation.id, params: removeColParams },
...intercepted.redos,
+ ...afterInterceptors.redos,
],
});
diff --git a/packages/sheets/src/commands/commands/set-col-visible.command.ts b/packages/sheets/src/commands/commands/set-col-visible.command.ts
index 992ca567ff..fb096add24 100644
--- a/packages/sheets/src/commands/commands/set-col-visible.command.ts
+++ b/packages/sheets/src/commands/commands/set-col-visible.command.ts
@@ -95,6 +95,12 @@ export const SetSpecificColsVisibleCommand: ICommand<ISetSpecificColsVisibleComm
const interceptedResult = sequenceExecute([...intercepted.redos], commandService);
if (result.result && interceptedResult.result) {
+ const afterInterceptors = sheetInterceptorService.afterCommandExecute({
+ id: SetSpecificColsVisibleCommand.id,
+ params,
+ });
+ sequenceExecute(afterInterceptors.redos, commandService);
+
const undoRedoService = accessor.get(IUndoRedoService);
undoRedoService.pushUndoRedo({
unitID: unitId,
@@ -102,12 +108,14 @@ export const SetSpecificColsVisibleCommand: ICommand<ISetSpecificColsVisibleComm
{ id: SetColHiddenMutation.id, params: undoMutationParams },
{ id: SetSelectionsOperation.id, params: undoSetSelectionsOperationParams },
...(intercepted.undos ?? []),
+ ...afterInterceptors.undos,
],
redoMutations: [
...(intercepted.preRedos ?? []),
{ id: SetColVisibleMutation.id, params: redoMutationParams },
{ id: SetSelectionsOperation.id, params: setSelectionOperationParams },
...intercepted.redos,
+ ...afterInterceptors.redos,
],
});
@@ -203,6 +211,12 @@ export const SetColHiddenCommand: ICommand = {
const interceptedResult = sequenceExecute([...intercepted.redos], commandService);
if (result.result && interceptedResult.result) {
+ const afterInterceptors = sheetInterceptorService.afterCommandExecute({
+ id: SetColHiddenCommand.id,
+ params: redoMutationParams,
+ });
+ sequenceExecute(afterInterceptors.redos, commandService);
+
const undoRedoService = accessor.get(IUndoRedoService);
undoRedoService.pushUndoRedo({
unitID: unitId,
@@ -210,12 +224,14 @@ export const SetColHiddenCommand: ICommand = {
{ id: SetColVisibleMutation.id, params: undoMutationParams },
{ id: SetSelectionsOperation.id, params: undoSetSelectionsOperationParams },
...(intercepted.undos ?? []),
+ ...afterInterceptors.undos,
],
redoMutations: [
...(intercepted.preRedos ?? []),
{ id: SetColHiddenMutation.id, params: redoMutationParams },
{ id: SetSelectionsOperation.id, params: setSelectionOperationParams },
...intercepted.redos,
+ ...afterInterceptors.redos,
],
});
return true;
diff --git a/packages/sheets/src/commands/commands/set-row-visible.command.ts b/packages/sheets/src/commands/commands/set-row-visible.command.ts
index 0a90108df9..ccd5320a60 100644
--- a/packages/sheets/src/commands/commands/set-row-visible.command.ts
+++ b/packages/sheets/src/commands/commands/set-row-visible.command.ts
@@ -96,6 +96,12 @@ export const SetSpecificRowsVisibleCommand: ICommand<ISetSpecificRowsVisibleComm
const interceptedResult = sequenceExecute([...intercepted.redos], commandService);
if (result.result && interceptedResult.result) {
+ const afterInterceptors = sheetInterceptorService.afterCommandExecute({
+ id: SetSpecificRowsVisibleCommand.id,
+ params,
+ });
+ sequenceExecute(afterInterceptors.redos, commandService);
+
undoRedoService.pushUndoRedo({
unitID: unitId,
undoMutations: [
@@ -103,12 +109,14 @@ export const SetSpecificRowsVisibleCommand: ICommand<ISetSpecificRowsVisibleComm
{ id: SetRowHiddenMutation.id, params: undoMutationParams },
{ id: SetSelectionsOperation.id, params: undoSetSelectionsOperationParams },
...(intercepted.undos ?? []),
+ ...afterInterceptors.undos,
],
redoMutations: [
...(intercepted.preRedos ?? []),
{ id: SetRowVisibleMutation.id, params: redoMutationParams },
{ id: SetSelectionsOperation.id, params: setSelectionOperationParams },
...intercepted.redos,
+ ...afterInterceptors.redos,
],
});
@@ -200,6 +208,12 @@ export const SetRowHiddenCommand: ICommand<ISetRowHiddenCommandParams> = {
], commandService);
if (execution.result) {
+ const afterInterceptors = sheetInterceptorService.afterCommandExecute({
+ id: SetRowHiddenCommand.id,
+ params: redoMutationParams,
+ });
+ sequenceExecute(afterInterceptors.redos, commandService);
+
undoRedoService.pushUndoRedo({
unitID: unitId,
undoMutations: [
@@ -207,12 +221,14 @@ export const SetRowHiddenCommand: ICommand<ISetRowHiddenCommandParams> = {
{ id: SetRowVisibleMutation.id, params: undoMutationParams },
{ id: SetSelectionsOperation.id, params: undoSetSelectionsOperationParams },
...(intercepted.undos ?? []),
+ ...afterInterceptors.undos,
],
redoMutations: [
...(intercepted.preRedos ?? []),
{ id: SetRowHiddenMutation.id, params: redoMutationParams },
{ id: SetSelectionsOperation.id, params: setSelectionOperationParams },
...intercepted.redos,
+ ...afterInterceptors.redos,
],
});
return true;
diff --git a/packages/sheets/src/commands/commands/set-worksheet-col-width.command.ts b/packages/sheets/src/commands/commands/set-worksheet-col-width.command.ts
index 5e90ee0cb8..faa1e0c685 100644
--- a/packages/sheets/src/commands/commands/set-worksheet-col-width.command.ts
+++ b/packages/sheets/src/commands/commands/set-worksheet-col-width.command.ts
@@ -218,10 +218,28 @@ export const SetColWidthCommand: ICommand = {
const result = sequenceExecute([...intercepted.redos, ...autoHeightRedos], commandService);
if (setColWidthResult && result.result) {
+ const afterInterceptors = sheetInterceptorService.afterCommandExecute({
+ id: SetColWidthCommand.id,
+ params: redoMutationParams,
+ });
+ sequenceExecute(afterInterceptors.redos, commandService);
+
undoRedoService.pushUndoRedo({
unitID: unitId,
- undoMutations: [...(intercepted.preUndos ?? []), { id: SetWorksheetColWidthMutation.id, params: undoMutationParams }, ...intercepted.undos, ...autoHeightUndos],
- redoMutations: [...(intercepted.preRedos ?? []), { id: SetWorksheetColWidthMutation.id, params: redoMutationParams }, ...intercepted.redos, ...autoHeightRedos],
+ undoMutations: [
+ ...(intercepted.preUndos ?? []),
+ { id: SetWorksheetColWidthMutation.id, params: undoMutationParams },
+ ...intercepted.undos,
+ ...afterInterceptors.undos,
+ ...autoHeightUndos,
+ ],
+ redoMutations: [
+ ...(intercepted.preRedos ?? []),
+ { id: SetWorksheetColWidthMutation.id, params: redoMutationParams },
+ ...intercepted.redos,
+ ...afterInterceptors.redos,
+ ...autoHeightRedos,
+ ],
});
return true;
diff --git a/packages/sheets/src/commands/commands/set-worksheet-row-height.command.ts b/packages/sheets/src/commands/commands/set-worksheet-row-height.command.ts
index 5086b38ad0..934e152b4e 100644
--- a/packages/sheets/src/commands/commands/set-worksheet-row-height.command.ts
+++ b/packages/sheets/src/commands/commands/set-worksheet-row-height.command.ts
@@ -153,6 +153,12 @@ export const DeltaRowHeightCommand: ICommand = {
const interceptedResult = sequenceExecute([...intercepted.redos], commandService);
if (result.result && interceptedResult.result) {
+ const afterInterceptors = sheetInterceptorService.afterCommandExecute({
+ id: DeltaRowHeightCommand.id,
+ params: redoMutationParams,
+ });
+ sequenceExecute(afterInterceptors.redos, commandService);
+
undoRedoService.pushUndoRedo({
unitID: unitId,
undoMutations: [
@@ -166,6 +172,7 @@ export const DeltaRowHeightCommand: ICommand = {
params: undoSetIsAutoHeightParams,
},
...intercepted.undos,
+ ...afterInterceptors.undos,
],
redoMutations: [
...(intercepted.preRedos ?? []),
@@ -178,6 +185,7 @@ export const DeltaRowHeightCommand: ICommand = {
params: redoSetIsAutoHeightParams,
},
...intercepted.redos,
+ ...afterInterceptors.redos,
],
});
return true;
@@ -254,6 +262,12 @@ export const SetRowHeightCommand: ICommand = {
const sheetInterceptorResult = sequenceExecute([...intercepted.redos], commandService);
if (result.result && sheetInterceptorResult.result) {
+ const afterInterceptors = sheetInterceptorService.afterCommandExecute({
+ id: SetRowHeightCommand.id,
+ params: redoMutationParams,
+ });
+ sequenceExecute(afterInterceptors.redos, commandService);
+
undoRedoService.pushUndoRedo({
unitID: unitId,
undoMutations: [
@@ -267,6 +281,7 @@ export const SetRowHeightCommand: ICommand = {
params: undoSetIsAutoHeightParams,
},
...intercepted.undos,
+ ...afterInterceptors.undos,
],
redoMutations: [
...intercepted.preRedos ?? [],
@@ -279,6 +294,7 @@ export const SetRowHeightCommand: ICommand = {
params: redoSetIsAutoHeightParams,
},
...intercepted.redos,
+ ...afterInterceptors.redos,
],
});
return true;