Skip to content

Enhancement: throttle scroll/wheel events to prevent skipping multiple slides on trackpad #5

@dpecos

Description

@dpecos

Description

On a trackpad or high-resolution mouse wheel, a single swipe or scroll gesture fires many wheel events in rapid succession. Because each event advances the slide, a short scroll can skip several slides at once, making navigation feel uncontrollable.

Current behaviour

src/mdeck/controllers/inputs/mouse.ts emits gotoNextSlide / gotoPreviousSlide on every wheel event with no rate limiting.

Expected behaviour

Scroll-based navigation should advance at most one slide per gesture, using a debounce or cooldown period (e.g. ~400 ms) between slide changes triggered by wheel events.

Suggested implementation

Add a timestamp-based cooldown in the wheel handler:

let lastScroll = 0;
const SCROLL_COOLDOWN_MS = 400;

element.addEventListener('wheel', (e) => {
  const now = Date.now();
  if (now - lastScroll < SCROLL_COOLDOWN_MS) return;
  lastScroll = now;
  e.deltaY > 0 ? events.emit('gotoNextSlide') : events.emit('gotoPreviousSlide');
});

Ported from gnab/remark#564

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions