diff --git a/src/components/image-editor/useImageCanvasAssetCanvasBridge.test.tsx b/src/components/image-editor/useImageCanvasAssetCanvasBridge.test.tsx index b1d3465cf..78815cf89 100644 --- a/src/components/image-editor/useImageCanvasAssetCanvasBridge.test.tsx +++ b/src/components/image-editor/useImageCanvasAssetCanvasBridge.test.tsx @@ -74,6 +74,7 @@ function AssetCanvasBridgeHarness({ appendCanvasLayersWithResources = vi.fn(), captureCanvasHistory = vi.fn(), selectSingleLayer = vi.fn(), + onAssetError = vi.fn(), }: { asset?: EditorAsset; resolveCanvasPoint?: (clientX: number, clientY: number) => { @@ -83,6 +84,7 @@ function AssetCanvasBridgeHarness({ appendCanvasLayersWithResources?: (nextLayers: CanvasLayer[]) => void; captureCanvasHistory?: () => void; selectSingleLayer?: (layerId: string | null) => void; + onAssetError?: (message: string) => void; }) { const assetPointerDragRef = useRef({ assetId: asset.id, @@ -128,6 +130,7 @@ function AssetCanvasBridgeHarness({ appendCanvasLayersWithResources, selectSingleLayer, addUploadedFiles: vi.fn(), + onAssetError, }); return ( @@ -224,6 +227,37 @@ describe('useImageCanvasAssetCanvasBridge', () => { expect(screen.getByTestId('hover').textContent).toBe('-'); }); + it('keeps the upload folder unchanged when layer creation fails', () => { + const appendCanvasLayersWithResources = vi.fn(); + const captureCanvasHistory = vi.fn(); + const onAssetError = vi.fn(); + render( + , + ); + + act(() => { + screen.getByRole('button', { name: '添加到画布' }).click(); + }); + + expect(screen.getByTestId('folder').textContent).toBe('project'); + expect(onAssetError).toHaveBeenCalledWith( + '角色动作素材“素材一”不完整:缺少可用序列帧。', + ); + expect(captureCanvasHistory).not.toHaveBeenCalled(); + expect(appendCanvasLayersWithResources).not.toHaveBeenCalled(); + }); + it('delegates active pointer drops over the canvas into the layer path', () => { const appendCanvasLayersWithResources = vi.fn(); render( diff --git a/src/components/image-editor/useImageCanvasAssetCanvasBridge.ts b/src/components/image-editor/useImageCanvasAssetCanvasBridge.ts index a3ada2954..b4fc4d1e0 100644 --- a/src/components/image-editor/useImageCanvasAssetCanvasBridge.ts +++ b/src/components/image-editor/useImageCanvasAssetCanvasBridge.ts @@ -156,7 +156,6 @@ export function useImageCanvasAssetCanvasBridge({ }: UseImageCanvasAssetCanvasBridgeOptions) { const addAssetLayer = useCallback( (asset: EditorAsset, position?: CanvasPoint) => { - setActiveUploadFolderId(asset.folderId); const nextLayerIndex = layerCounterRef.current + 1; let nextLayer: CanvasLayer; try { @@ -176,6 +175,7 @@ export function useImageCanvasAssetCanvasBridge({ ); return; } + setActiveUploadFolderId(asset.folderId); layerCounterRef.current = nextLayerIndex; captureCanvasHistory({ type: 'add-image', count: 1 }); appendCanvasLayersWithResources([nextLayer]);