Skip to content

fix: remove 250ms movement lockout and refactor gesture handling#77

Open
Nakshatra480 wants to merge 3 commits intoAOSSIE-Org:mainfrom
Nakshatra480:fix/trackpad-lag-issue-76
Open

fix: remove 250ms movement lockout and refactor gesture handling#77
Nakshatra480 wants to merge 3 commits intoAOSSIE-Org:mainfrom
Nakshatra480:fix/trackpad-lag-issue-76

Conversation

@Nakshatra480
Copy link

@Nakshatra480 Nakshatra480 commented Feb 12, 2026

Closes #76

Overview

The trackpad previously felt laggy or "stuck" during rapid swipes and multi-touch transitions due to an artificial 250ms lockout period.

Changes

  • Fixed Movement Lag: Removed the redundant lastEndTimeStamp check in handleTouchMove. This check was blocking all movement events for 250ms every time a finger was lifted, causing noticeable input delay.
  • Refactored Gesture Logic: Abstracted the message-sending logic into a new processMovement helper function. This makes the code more readable and easier to maintain without changing the core behavior.
  • Cleanup: Removed the now-obsolete lastEndTimeStamp reference and its associated logic to keep the hook clean and focused.

Technical Rationale

The moved.current flag already correctly handles the distinction between a "Tap" and a "Move" based on touch distance and initial duration. The additional timestamp check created a blackout period that interrupted the coordinate stream, especially during fluid gestures like two-finger scrolling. Removing this restores natural, real-time responsiveness.

Verification Results

  • Tested rapid swiping: Cursor responds immediately without the previous "dead zone."
  • Tested multi-touch transitions: Lifting one finger during a scroll no longer freezes the remaining input.
  • Verified tap-to-click: Still works as expected since the distance-based logic remains intact.

Summary by CodeRabbit

  • Refactor
    • Overhauled touch gesture handling to route movements through a unified processing flow, improving consistency for drag, pinch/zoom, and two-finger scroll interactions.
  • Bug Fixes
    • Reduced missed or delayed movement recognition and removed time-based gating, yielding more responsive and reliable tap/click, drag, scroll, and pinch behaviors on touch devices.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 12, 2026

📝 Walkthrough

Walkthrough

Refactors touch gesture handling in useTrackpadGesture.ts by adding a centralized processMovement(sumX, sumY) helper, removing the lastEndTimeStamp timing gate, and routing movement/scroll/zoom/drag decisions by finger count and moved/drag state instead of timestamps.

Changes

Cohort / File(s) Summary
Touch Gesture Handler Refactor
src/hooks/useTrackpadGesture.ts
Introduces processMovement(sumX, sumY) to centralize movement handling; removes lastEndTimeStamp and all time-gated checks; touchMove now calls processMovement when movement detected; touchStart/touchEnd simplified (no timestamp side-effects); two-finger pinch/scroll/zoom and single-finger drag routing consolidated.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐰 I nudged the timestamps out the door,
One helper now guides each hop and score,
Fingers dance, no pauses stay,
Smooth trails hop on, come what may—
✨🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: removing the 250ms movement lockout and refactoring gesture handling logic in useTrackpadGesture.ts.
Linked Issues check ✅ Passed The PR successfully implements all coding requirements from issue #76: removes the lastEndTimeStamp timestamp check blocking movement, refactors message logic into processMovement helper, and relies on existing moved.current flag for tap/move distinction.
Out of Scope Changes check ✅ Passed All changes are directly scoped to removing the 250ms lockout and refactoring gesture handling in useTrackpadGesture.ts; no unrelated modifications are present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

No actionable comments were generated in the recent review. 🎉

🧹 Recent nitpick comments
src/hooks/useTrackpadGesture.ts (1)

58-65: Inconsistent rounding on scroll deltas in the non-scroll-mode two-finger path.

Lines 62–63 send raw floating-point values (-sumX * sensitivity * invertMult), while the scroll path at lines 80–81 and the move paths at lines 45–46 / 86–87 all round to one decimal place. This can cause subtle jitter differences between the two scroll paths.

Proposed fix
             } else {
                 lastPinchDist.current = dist;
                 send({ 
                     type: 'scroll', 
-                    dx: -sumX * sensitivity * invertMult, 
-                    dy: -sumY * sensitivity * invertMult 
+                    dx: Math.round(-sumX * sensitivity * 10 * invertMult) / 10, 
+                    dy: Math.round(-sumY * sensitivity * 10 * invertMult) / 10 
                 });
             }

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/hooks/useTrackpadGesture.ts`:
- Around line 39-56: The processMovement function currently prioritizes
scrollMode over dragging which causes drag gestures to be treated as scrolls;
update processMovement so that the dragging state is checked before the
scrollMode/ongoingTouches length branch: if dragging.current is true (or
ongoingTouches.current.length === 1 && dragging.current) send the 'move' event
via send({ type: 'move', dx: ..., dy: ... }) and return, otherwise proceed with
the existing two-finger/pinch and scrollMode logic (keep getTouchDistance,
lastPinchDist.current, pinching.current, sensitivity and ongoingTouches.current
checks intact) so drags always emit move events even when scrollMode is enabled.
🧹 Nitpick comments (2)
src/hooks/useTrackpadGesture.ts (2)

39-56: Unused parameter e in processMovement.

The e: React.TouchEvent parameter is accepted but never referenced inside the function body.

🧹 Remove unused parameter
-    const processMovement = (sumX: number, sumY: number, e: React.TouchEvent) => {
+    const processMovement = (sumX: number, sumY: number) => {

And at the call site (Line 151):

-            processMovement(sumX, sumY, e);
+            processMovement(sumX, sumY);

24-34: Consider cleaning up draggingTimeout on unmount to avoid firing send after the component is gone.

This is pre-existing, but since the hook is being refactored, it may be worth adding a cleanup effect. A stale timeout could call send after unmount.

Example: add cleanup via useEffect

Add at the end of the hook body (before the return):

import { useRef, useState, useEffect } from 'react';

// ... inside the hook, before return:
useEffect(() => {
    return () => {
        if (draggingTimeout.current) {
            clearTimeout(draggingTimeout.current);
        }
    };
}, []);

@Nakshatra480 Nakshatra480 marked this pull request as draft February 12, 2026 14:23
@Nakshatra480 Nakshatra480 force-pushed the fix/trackpad-lag-issue-76 branch from ba8c938 to faab94f Compare February 12, 2026 14:33
@Nakshatra480 Nakshatra480 force-pushed the fix/trackpad-lag-issue-76 branch from 2c8d67f to 1d09f65 Compare February 12, 2026 14:41
@Nakshatra480 Nakshatra480 reopened this Feb 12, 2026
@Nakshatra480 Nakshatra480 marked this pull request as ready for review February 12, 2026 16:30
@Nakshatra480
Copy link
Author

Nakshatra480 commented Feb 12, 2026

@imxade Please review this PR where I've implemented the following improvements:

  • Removed the lastEndTimeStamp check to fix the 250ms lockout and ensure instant trackpad responsiveness.
  • Consolidated the gesture handling into a single processMovement helper for a cleaner and more maintainable structure.
  • Prioritized the dragging state so that drag-and-drop works correctly even when scroll mode is active.
  • Unified coordinate rounding and sensitivity scaling to provide consistent and precise input handling.

Thanks for your time and effort.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: 250ms movement lockout after lifting finger causes trackpad lag

1 participant