Skip to content

fix: reset mouse drag state on window mouseup to prevent stuck drawing outside grid#488

Open
Xenon010101 wants to merge 1 commit into
algoscope-hq:mainfrom
Xenon010101:fix/bug-484-mouse-drag-outside-grid
Open

fix: reset mouse drag state on window mouseup to prevent stuck drawing outside grid#488
Xenon010101 wants to merge 1 commit into
algoscope-hq:mainfrom
Xenon010101:fix/bug-484-mouse-drag-outside-grid

Conversation

@Xenon010101
Copy link
Copy Markdown
Contributor

@Xenon010101 Xenon010101 commented May 30, 2026

Description

When drawing walls/weights on the grid, releasing the mouse button outside the grid container or browser window left \mousePressed\ stuck as \ rue. Moving back over the grid would continue drawing unintentionally.

Fix

Added a \useEffect\ that listens for \mouseup\ on \window. This ensures the drag state is always reset regardless of where the mouse button is released (inside the grid, outside the container, or outside the browser window).

The cleanup function removes the listener on unmount to prevent memory leaks.

Related Issue

Fixes #484

Summary by CodeRabbit

  • Bug Fixes
    • Fixed the grid visualization to stop drawing when the mouse button is released outside the grid area, preventing unintended shapes from being created during extended drag operations.

Review Change Stack

@netlify
Copy link
Copy Markdown

netlify Bot commented May 30, 2026

Deploy Preview for astounding-nougat-da0f6a ready!

Name Link
🔨 Latest commit b315896
🔍 Latest deploy log https://app.netlify.com/projects/astounding-nougat-da0f6a/deploys/6a1a911677b40f0008d108c3
😎 Deploy Preview https://deploy-preview-488--astounding-nougat-da0f6a.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 30, 2026

@Xenon010101 is attempting to deploy a commit to the adityapaul2603-gmailcom's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 30, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro Plus

Run ID: ab3d2862-b6c8-49ba-8018-dfb82824ea9c

📥 Commits

Reviewing files that changed from the base of the PR and between 9f6f2f6 and b315896.

📒 Files selected for processing (1)
  • src/components/shortestPathAlgo/GridVisualizer.jsx

📝 Walkthrough

Walkthrough

This PR fixes a bug where grid drawing remains "stuck" after the user releases the mouse button outside the grid container. A window-level mouseup listener now clears the mousePressed state globally, ensuring the grid stops drawing even if the mouse is released beyond the grid boundaries.

Changes

Off-grid mouseup handling

Layer / File(s) Summary
Window mouseup listener for drag state reset
src/components/shortestPathAlgo/GridVisualizer.jsx
useEffect installs a window mouseup listener that sets mousePressed to false, with proper cleanup on unmount. This prevents the grid from continuing drag-based drawing (walls, weights) after the mouse button is released outside the grid area.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Suggested labels

gssoc:approved, level:intermediate

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Algorithm Complexity ✅ Passed PR contains no algorithm implementation changes—only an event handling bug fix for mouse drag state. The custom check for algorithm complexity is not applicable to this PR.
Conventional Commits ✅ Passed PR title and commit message both follow conventional commits standards with proper "fix:" prefix, clear description of the mouse drag state reset fix, and appropriate message formatting.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

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: Mouse dragging continues if released outside the grid container

1 participant