Skip to content

Centralize gesture state reset logic in useTrackpadGesture#286

Closed
Shashank-Mengani wants to merge 2 commits intoAOSSIE-Org:mainfrom
Shashank-Mengani:fix-gestures
Closed

Centralize gesture state reset logic in useTrackpadGesture#286
Shashank-Mengani wants to merge 2 commits intoAOSSIE-Org:mainfrom
Shashank-Mengani:fix-gestures

Conversation

@Shashank-Mengani
Copy link

@Shashank-Mengani Shashank-Mengani commented Mar 11, 2026

…file

Addressed Issues:

Fixes #(281)

Description

This PR centralizes the gesture state reset logic inside the
useTrackpadGesture hook.

Previously, gesture-related refs were reset in multiple places across the
hook, which made the code harder to maintain and increased the risk of
missing state variables when introducing new gesture states.

This change introduces a helper function resetGestureState() that
consolidates the reset logic for:

  • ongoingTouches
  • moved
  • releasedCount
  • dragging
  • lastPinchDist
  • pinching
  • draggingTimeout

All gesture reset logic is now handled in one place, improving
maintainability and reducing duplicated code.

Screenshots/Recordings:

Not applicable — this PR only refactors internal gesture state logic
without changing UI or user-visible behavior.

Functional Verification

  • Please check off the behaviors verified with this change.

Screen Mirror

  • Screen Mirror works.

Authentication

  • Connection doesn't work without a valid token.

Basic Gestures

  • One-finger tap: Verified as Left Click.

  • Two-finger tap: Verified as Right Click.

  • Click and drag: Verified selection behavior.

  • Pinch to zoom: Verified zoom functionality (if applicable).

Modes & Settings

  • Cursor mode: Cursor moves smoothly and accurately.

  • Scroll mode: Page scrolls as expected.

  • Sensitivity: Verified changes in cursor speed/sensitivity settings.

  • Copy and Paste: Verified both Copy and Paste functionality.

  • Invert Scrolling: Verified scroll direction toggles correctly.

Advanced Input

  • Key combinations: Verified "hold" behavior for modifiers (e.g., Ctrl+C) and held keys are shown in buffer.

  • Keyboard input: Verified Space, Backspace, and Enter keys work correctly.

  • Glide typing: Verified path drawing and text output.

  • Voice input: Verified speech-to-text functionality for full sentences.

  • Backspace doesn't send the previous input.

Any other gesture or input behavior introduced:

None. This PR does not introduce new gestures.
It only refactors internal state reset logic.

  • New Gestures: Verified any other gesture or input behavior introduced in this PR.

Additional Notes:

This change preserves the existing gesture behavior and only improves
code maintainability by centralizing gesture state reset logic.

Checklist

  • My PR addresses a single issue, fixes a single bug or makes a single improvement.

  • My code follows the project's code style and conventions

  • I have performed a self-review of my own code

  • I have commented my code, particularly in hard-to-understand areas

  • If applicable, I have made corresponding changes or additions to the documentation

  • If applicable, I have made corresponding changes or additions to tests

  • My changes generate no new warnings or errors

  • I have joined the and I will share a link to this PR with the project maintainers there

  • I have read the

  • Once I submit my PR, CodeRabbit AI will automatically review it and I will address CodeRabbit's comments.

  • Incase of UI change I've added a demo video.

⚠️ AI Notice - Important!
We encourage contributors to use AI tools responsibly when creating Pull Requests. While AI can be a valuable aid, it is essential to ensure that your contributions meet the task requirements, build successfully, include relevant tests, and pass all linters. Submissions that do not meet these standards may be closed without warning to maintain the quality and integrity of the project. Please take the time to understand the changes you are proposing and their impact.

Summary by CodeRabbit

  • Refactor
    • Consolidated internal gesture state cleanup and standardized gesture payload shapes for more consistent handling.
    • Reorganized gesture flow and minor structural tweaks to improve maintainability.
    • No changes to existing gesture behavior or public interfaces; user-facing interactions remain the same.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 11, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 48f3e025-19e8-44cb-9c49-0af531c5d552

📥 Commits

Reviewing files that changed from the base of the PR and between 161bd29 and 50df3da.

📒 Files selected for processing (1)
  • src/hooks/useTrackpadGesture.ts

Walkthrough

Introduces a centralized resetGestureState(preserveDraggingTimeout) helper and refactors touch handling to use it; standardizes pinch-zoom distance/delta computation and normalizes payload shapes for scroll/zoom, without changing public API.

Changes

Cohort / File(s) Summary
Gesture State & Touch Handling
src/hooks/useTrackpadGesture.ts
Adds resetGestureState(preserveDraggingTimeout) to centralize cleanup of ongoingTouches, moved, releasedCount, dragging, lastPinchDist, and pinching; refactors end-of-gesture flow to call it, adjusts two-finger pinch distance/delta computation, and standardizes scroll/zoom payload shapes and spacing. Minor comment and initialization tweaks; public API unchanged.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

Typescript Lang

Poem

🐰
Tiny paws tap, then fingers part,
I tidy states with gentle art.
A helper hops, the chaos clears,
Pinches count and dragging steers.
Hooray — clean hops and fewer tears!

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: centralizing gesture state reset logic in useTrackpadGesture, which matches the core refactoring work described in the changeset.
Description check ✅ Passed The description is well-structured with addressed issues, clear explanation of changes, functional verification notes, and additional context about maintaining existing behavior.

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

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

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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/hooks/useTrackpadGesture.ts`:
- Around line 58-61: resetGestureState currently unconditionally clears the
pending left-click timeout (draggingTimeout.current), which cancels the deferred
mouse-up scheduled in handleTouchEnd and causes tap/drag state to break; change
resetGestureState (or its callers) so it does not clear draggingTimeout.current
by default — either add a boolean parameter (e.g., preserveLeftClickTimeout) or
split out a separate clearTimers function and only clear draggingTimeout.current
when you really want to cancel the pending left-click; update calls from
handleTouchEnd/anywhere that need to preserve the deferred mouse-up to call
resetGestureState(..., preserveLeftClickTimeout=true) or call the new split
function accordingly, keeping references to draggingTimeout.current in those
places (symbols: resetGestureState, handleTouchEnd, draggingTimeout.current).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: eca455e8-2754-4176-9667-f729d2e20f33

📥 Commits

Reviewing files that changed from the base of the PR and between 3c85686 and 161bd29.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (1)
  • src/hooks/useTrackpadGesture.ts

@Shashank-Mengani
Copy link
Author

Shashank-Mengani commented Mar 11, 2026 via email

@imxade
Copy link
Contributor

imxade commented Mar 12, 2026

I only see added code and removed comments without reduction in redundancy

@imxade imxade closed this Mar 12, 2026
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.

2 participants