From 1d52ebb337fb83a5d52a3909df3cb45639b84ef8 Mon Sep 17 00:00:00 2001 From: VicKun Date: Mon, 19 Jan 2026 17:33:59 +0800 Subject: [PATCH] feat(drawing): add interceptor for drawing update (#6490) --- .../commands/set-sheet-drawing.command.ts | 41 ++++++++++++------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/packages/sheets-drawing-ui/src/commands/commands/set-sheet-drawing.command.ts b/packages/sheets-drawing-ui/src/commands/commands/set-sheet-drawing.command.ts index 38f3a76a2c..414c29b234 100644 --- a/packages/sheets-drawing-ui/src/commands/commands/set-sheet-drawing.command.ts +++ b/packages/sheets-drawing-ui/src/commands/commands/set-sheet-drawing.command.ts @@ -15,17 +15,19 @@ */ import type { IAccessor, ICommand } from '@univerjs/core'; +import type { IDrawingJsonUndo1 } from '@univerjs/drawing'; + +import type { ISheetDrawing } from '@univerjs/sheets-drawing'; +import type { ISetDrawingCommandParams } from './interfaces'; import { CommandType, ICommandService, IUndoRedoService, + sequenceExecute, } from '@univerjs/core'; - -import type { ISheetDrawing } from '@univerjs/sheets-drawing'; +import { SheetInterceptorService } from '@univerjs/sheets'; import { DrawingApplyType, ISheetDrawingService, SetDrawingApplyMutation } from '@univerjs/sheets-drawing'; -import type { IDrawingJsonUndo1 } from '@univerjs/drawing'; import { ClearSheetDrawingTransformerOperation } from '../operations/clear-drawing-transformer.operation'; -import type { ISetDrawingCommandParams } from './interfaces'; /** * The command to update defined name @@ -37,6 +39,7 @@ export const SetSheetDrawingCommand: ICommand = { const commandService = accessor.get(ICommandService); const undoRedoService = accessor.get(IUndoRedoService); const sheetDrawingService = accessor.get(ISheetDrawingService); + const sheetInterceptorService = accessor.get(SheetInterceptorService); if (!params) return false; @@ -49,20 +52,30 @@ export const SetSheetDrawingCommand: ICommand = { const { unitId, subUnitId, undo, redo, objects } = jsonOp; - // execute do mutations and add undo mutations to undo stack if completed - const result = commandService.syncExecuteCommand(SetDrawingApplyMutation.id, { unitId, subUnitId, op: redo, objects, type: DrawingApplyType.UPDATE }); + const intercepted = sheetInterceptorService.onCommandExecute({ id: SetSheetDrawingCommand.id, params }); + const redoMutations = [ + ...(intercepted.preRedos ?? []), + { id: SetDrawingApplyMutation.id, params: { unitId, subUnitId, op: redo, objects, type: DrawingApplyType.UPDATE } }, + ...intercepted.redos, + { id: ClearSheetDrawingTransformerOperation.id, params: [unitId] }, + ]; + const undoMutations = [ + ...(intercepted.preUndos ?? []), + { id: SetDrawingApplyMutation.id, params: { unitId, subUnitId, op: undo, objects, type: DrawingApplyType.UPDATE } }, + ...intercepted.undos, + { id: ClearSheetDrawingTransformerOperation.id, params: [unitId] }, + ]; + + // execute do mutations and add undo mutations to undo stack if completed + // const result = commandService.syncExecuteCommand(SetDrawingApplyMutation.id, { unitId, subUnitId, op: redo, objects, type: DrawingApplyType.UPDATE }); + + const result = sequenceExecute(redoMutations, commandService); if (result) { undoRedoService.pushUndoRedo({ unitID: unitId, - undoMutations: [ - { id: SetDrawingApplyMutation.id, params: { unitId, subUnitId, op: undo, objects, type: DrawingApplyType.UPDATE } }, - { id: ClearSheetDrawingTransformerOperation.id, params: [unitId] }, - ], - redoMutations: [ - { id: SetDrawingApplyMutation.id, params: { unitId, subUnitId, op: redo, objects, type: DrawingApplyType.UPDATE } }, - { id: ClearSheetDrawingTransformerOperation.id, params: [unitId] }, - ], + undoMutations, + redoMutations, }); return true;