diff --git a/packages/core/src/services/EventsHandler.ts b/packages/core/src/services/EventsHandler.ts index 4c4f79513..8408561dc 100644 --- a/packages/core/src/services/EventsHandler.ts +++ b/packages/core/src/services/EventsHandler.ts @@ -95,7 +95,7 @@ export class EventsHandler extends AbstractService { }; private readonly step = new Step(); - private readonly keyHandler = new PressHandler(); + private readonly keyHandler = new PressHandler(); private readonly resizeObserver = new ResizeObserver(throttle(() => this.viewer.autoSize(), 50)); private readonly moveThreshold = MOVE_THRESHOLD * SYSTEM.pixelRatio; @@ -207,7 +207,7 @@ export class EventsHandler extends AbstractService { case ACTIONS.ZOOM_OUT: this.viewer.dynamics.zoom.roll(true); break; } - this.keyHandler.down(); + this.keyHandler.down(action); e.preventDefault(); } } @@ -222,10 +222,13 @@ export class EventsHandler extends AbstractService { return; } - this.keyHandler.up(() => { - this.viewer.dynamics.position.stop(); - this.viewer.dynamics.zoom.stop(); - this.viewer.resetIdleTimer(); + this.keyHandler.up((action) => { + if (action === ACTIONS.ZOOM_IN || action === ACTIONS.ZOOM_OUT) { + this.viewer.dynamics.zoom.stop(); + } else { + this.viewer.dynamics.position.stop(); + this.viewer.resetIdleTimer(); + } }); } diff --git a/packages/core/src/utils/PressHandler.ts b/packages/core/src/utils/PressHandler.ts index 1c4353b99..62c79c1d4 100644 --- a/packages/core/src/utils/PressHandler.ts +++ b/packages/core/src/utils/PressHandler.ts @@ -3,9 +3,10 @@ * When the pressed thing goes up and was not pressed long enough, wait a bit more before execution * @internal */ -export class PressHandler { +export class PressHandler { private time = 0; private timeout: ReturnType; + private data: TData; get pending() { return this.time !== 0; @@ -15,16 +16,17 @@ export class PressHandler { this.delay = delay; } - down() { + down(data?: TData) { if (this.timeout) { clearTimeout(this.timeout); this.timeout = undefined; } this.time = new Date().getTime(); + this.data = data; } - up(cb: () => void) { + up(cb: (data: TData) => void) { if (!this.time) { return; } @@ -32,13 +34,15 @@ export class PressHandler { const elapsed = Date.now() - this.time; if (elapsed < this.delay) { this.timeout = setTimeout(() => { - cb(); + cb(this.data); this.timeout = undefined; this.time = 0; + this.data = undefined; }, this.delay); } else { - cb(); + cb(this.data); this.time = 0; + this.data = undefined; } } }