Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/media-editor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Bug Fixes

- Stop a pan drag started just after a wheel zoom from recording one undo entry per frame. The drag now ends the pending wheel gesture instead of letting its debounce timer close the drag's gesture mid-drag ([#83558](https://github.com/WordPress/gutenberg/pull/83558)).

## 0.19.0 (2026-09-23)

### Bug Fixes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,14 @@ export class InteractionController {
// Capture pointer so drag works across iframe boundaries.
el.setPointerCapture( e.pointerId );

// End a pending wheel gesture now, so its debounce timer cannot
// fire mid-drag and end the drag's gesture along with it.
if ( this.wheelGestureActive ) {
clearTimeout( this.wheelGestureTimer );
this.wheelGestureActive = false;
this.options.onGestureEnd?.();
}

this.setStatus( { isDragging: true } );
this.options.onGestureStart?.();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,51 @@ describe( 'InteractionController', () => {

vi.useRealTimers();
} );

it( 'does not end the gesture mid-drag when the drag starts within the wheel debounce', () => {
vi.useFakeTimers( {
toFake: [ 'setTimeout', 'clearTimeout' ],
} );
const state = makeState( { zoom: 2 } );
const calls: string[] = [];
const { controller } = createController( state, {
onGestureStart: () => calls.push( 'start' ),
onGestureEnd: () => calls.push( 'end' ),
} );
const el = createMockElement();

// Zoom, then start dragging before the 300ms debounce elapses.
controller.handleWheel(
createWheelEvent( { deltaY: -50, currentTarget: null } )
);
vi.advanceTimersByTime( 100 );
controller.handlePointerDown(
createPointerEvent( { clientX: 100, clientY: 100 } ),
el
);
const dragStartIndex = calls.lastIndexOf( 'start' );

// Keep dragging past the point where the debounce fires.
el._fire(
'pointermove',
createPointerEvent( { clientX: 110, clientY: 100 } )
);
vi.advanceTimersByTime( 350 );
el._fire(
'pointermove',
createPointerEvent( { clientX: 120, clientY: 100 } )
);
const callsDuringDrag = calls.slice( dragStartIndex + 1 );

el._fire( 'pointerup', createPointerEvent() );
vi.useRealTimers();

expect( actionMocks.setPan ).toHaveBeenCalledTimes( 2 );
// An end here closes the undo batch, so every later pan frame
// records its own undo entry.
expect( callsDuringDrag ).not.toContain( 'end' );
expect( calls[ calls.length - 1 ] ).toBe( 'end' );
} );
} );

describe( 'keyboard', () => {
Expand Down
Loading