Skip to content

fix: forward mouse drag events in buttonEventTracking mode#519

Open
gi11es wants to merge 3 commits into
migueldeicaza:mainfrom
gi11es:fix/mouse-drag-button-tracking
Open

fix: forward mouse drag events in buttonEventTracking mode#519
gi11es wants to merge 3 commits into
migueldeicaza:mainfrom
gi11es:fix/mouse-drag-button-tracking

Conversation

@gi11es

@gi11es gi11es commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #87

  • mouseDragged only forwarded drag events when mouseMode was .anyEvent (via sendMotionEvent()), but tmux uses .buttonEventTracking (CSI ? 1002 h) which also requires drag event forwarding for pane resize and mouse text selection.
  • Changed the guard condition from sendMotionEvent() to sendButtonTracking(), which returns true for both buttonEventTracking and anyEvent modes.

Reproduction

  1. Open a tmux session inside SwiftTerm
  2. Try to resize a pane by dragging the border
  3. Before fix: nothing happens — drag events are silently dropped
  4. After fix: pane resizes correctly, mouse selection works

Test plan

  • Added MouseTrackingTests with 14 tests covering:
    • MouseMode.sendButtonTracking() returns correct values for all 5 enum cases
    • MouseMode.sendMotionEvent() returns correct values for all 5 enum cases
    • sendButtonTracking() is a superset of sendMotionEvent() (the invariant this fix relies on)
    • Integration: motion events produce SGR output when buttonEventTracking is active
    • Integration: motion events produce SGR output when anyEvent is active (regression guard)
    • Negative: off and vt200 modes do not pass the sendButtonTracking() check
    • SGR encoding format matches what tmux expects (<32;col;row M)
  • All 14 tests pass via swift test --filter MouseTrackingTests

🤖 Generated with Claude Code

…caza#87)

mouseDragged only forwarded drag events for anyEvent mouse mode
(sendMotionEvent), but tmux uses buttonEventTracking (CSI ? 1002 h)
which also needs drag forwarding for pane resize and text selection.

Change the guard from sendMotionEvent() to sendButtonTracking() which
covers both buttonEventTracking and anyEvent modes.

Add MouseTrackingTests with 14 tests covering:
- MouseMode.sendButtonTracking() for all enum cases
- MouseMode.sendMotionEvent() for all enum cases
- Superset relationship between the two predicates
- Integration tests verifying motion events are forwarded in
  buttonEventTracking and anyEvent modes via Terminal + delegate
- Negative tests for off and vt200 modes
- SGR encoding format verification

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

Mouse selection under tmux is broken

2 participants