Fix issue where drag-to-cut-selection action would move the original Layer on long async operations

This commit is contained in:
Igor Zinken
2026-04-25 10:45:46 +02:00
parent 1277ba49d4
commit a4a86acb64
2 changed files with 26 additions and 4 deletions

View File

@@ -54,6 +54,10 @@ export function startLayerDrag( store: Store<BitMapperyState>, layer: Layer, x:
const orgSelection = clone( activeDocument.activeSelection );
const selectionBoundingBox = selectionToRectangle( orgSelection );
if ( isPointerDrag ) {
pointerUp( renderer, x, y );
}
copySelection( activeDocument, layer )
.then( selectionContent => {
const bitmapWithoutSelection = deleteSelectionContent( activeDocument, layer );
@@ -77,19 +81,18 @@ export function startLayerDrag( store: Store<BitMapperyState>, layer: Layer, x:
renderer?.resetFilterAndRecache();
};
const commit = (): void => {
const commit = ( maintainDrag = false ): void => {
replaceSource( bitmapWithoutSelection );
store.commit( "insertLayerAtIndex", { index: insertIndex, layer: newLayer });
queueMicrotask(() => {
store.commit( "setActiveSelection", [] );
if ( isPointerDrag ) {
pointerUp( renderer, x, y );
if ( isPointerDrag && maintainDrag ) {
pointerDown( getRendererForLayer( newLayer ), x, y );
}
});
};
commit();
commit( true );
enqueueState( `startLayerDrag_${layer.id}`, {
undo(): void {

View File

@@ -268,5 +268,24 @@ describe( "layer drag start action", () => {
expect( mockPointerUp ).not.toHaveBeenCalled();
});
});
describe( "and redo-ing the action", () => {
it( "should not invoke the pointer down event on the recreated Layer", async () => {
startLayerDrag( store, layer, 10, 10, true );
await flushPromises();
const { undo, redo } = mockEnqueueState.mock.calls[ 0 ][ 1 ];
undo();
vi.resetAllMocks();
redo();
await flushPromises();
expect( mockPointerDown ).not.toHaveBeenCalled();
});
});
});
});