Skip to content

Fix: Don't cancel bounding box drawing when mouse leaves canvas#14

Open
iwconfig wants to merge 1 commit into
hirune924:masterfrom
iwconfig:fix-mouseleave-bounding-box
Open

Fix: Don't cancel bounding box drawing when mouse leaves canvas#14
iwconfig wants to merge 1 commit into
hirune924:masterfrom
iwconfig:fix-mouseleave-bounding-box

Conversation

@iwconfig

Copy link
Copy Markdown

When drawing a bounding box, if the cursor leaves the canvas area, the selection is no longer cancelled. Instead:

  • The box edge is clamped to canvas boundary while outside
  • Mouse position is tracked globally while outside
  • Box creation completes normally when mouse re-enters and releases
  • If released outside canvas, box is created with edge at canvas boundary

Implementation details:

  • Uses isOutside state to track when cursor is outside canvas
  • Global event handlers only attached when both drawing AND outside canvas
  • addingRef provides synchronous access to adding state in event handlers
  • Immediate ref update in createBoundingBox prevents race conditions

This improves UX when drawing large boxes that may require the cursor to briefly exit the canvas area.

When drawing a bounding box, if the cursor leaves the canvas area,
the selection is no longer cancelled. Instead:
- The box edge is clamped to canvas boundary while outside
- Mouse position is tracked globally while outside
- Box creation completes normally when mouse re-enters and releases
- If released outside canvas, box is created with edge at canvas boundary

Implementation details:
- Uses isOutside state to track when cursor is outside canvas
- Global event handlers only attached when both drawing AND outside canvas
- addingRef provides synchronous access to adding state in event handlers
- Immediate ref update in createBoundingBox prevents race conditions

This improves UX when drawing large boxes that may require the cursor
to briefly exit the canvas area.
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.

1 participant