mirror of
https://github.com/igorski/bitmappery.git
synced 2026-06-16 19:25:38 +02:00
Fix issue where drag-to-cut-selection action would move the original Layer on long async operations
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user