Skip to content

tmux stuff#717

Open
austinywang wants to merge 1 commit intomainfrom
cmux/tmux-bindings
Open

tmux stuff#717
austinywang wants to merge 1 commit intomainfrom
cmux/tmux-bindings

Conversation

@austinywang
Copy link
Contributor

@austinywang austinywang commented Mar 1, 2026

Summary by CodeRabbit

  • New Features

    • Command-key shortcuts are now intelligently routed to the terminal when appropriate, while preserving app-level behavior for preferences and copy operations.
  • Tests

    • Added comprehensive test coverage for command shortcut routing behavior across multiple scenarios.
@vercel
Copy link

vercel bot commented Mar 1, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
cmux Ready Ready Preview, Comment Mar 1, 2026 7:32am
@coderabbitai
Copy link

coderabbitai bot commented Mar 1, 2026

📝 Walkthrough

Walkthrough

This PR introduces a new terminal command-shortcut routing mechanism that enables Command-key shortcuts to be passed through to the Ghostty terminal view instead of being handled by the app's menu system. A new function shouldRouteTerminalCommandShortcutToGhostty() evaluates modifier flags and terminal state to decide routing, while preserving special cases for Preferences (Cmd+,) and copy behavior when text is selected. Corresponding test coverage validates the routing logic across multiple scenarios.

Changes

Cohort / File(s) Summary
Terminal Command-Shortcut Routing Implementation
Sources/AppDelegate.swift
Adds shouldRouteTerminalCommandShortcutToGhostty() function to evaluate whether Command-key shortcuts should route to Ghostty based on modifier flags, key codes, and terminal selection state. Integrates routing decision into NSWindow key-event handler to send qualifying events to Ghostty terminal view instead of app menu logic.
Routing Logic Test Suite
cmuxTests/CmuxWebViewKeyEquivalentTests.swift
Introduces TerminalCommandShortcutRoutingPolicyTests class with five test cases covering: Command+C routing with and without selection, Cmd+, preservation for Preferences, Command modifier requirement validation, and routing of other Command-modifier shortcuts to terminal.

Sequence Diagram

sequenceDiagram
    participant User
    participant NSWindow
    participant Router as shouldRouteTerminalCommand<br/>ShortcutToGhostty()
    participant GhosttyView as Ghostty Terminal View
    participant AppMenu as App Menu System
    
    User->>NSWindow: Press Command+Key
    NSWindow->>NSWindow: cmux_performKeyEquivalent
    NSWindow->>NSWindow: Check if Ghostty view focused
    alt Ghostty view focused
        NSWindow->>Router: Evaluate routing decision<br/>(flags, keyCode, selection)
        alt Should route to Ghostty
            Router-->>NSWindow: Return true
            NSWindow->>GhosttyView: keyDown(with:event)
            GhosttyView->>User: Handle shortcut in terminal
        else Keep in app (Cmd+, or selection)
            Router-->>NSWindow: Return false
            NSWindow->>AppMenu: Handle via menu system
            AppMenu->>User: Execute app-level action
        end
    else Ghostty not focused
        NSWindow->>AppMenu: Handle via menu system
        AppMenu->>User: Execute app-level action
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 A hop through Command-key lands so bright,
Where shortcuts find their destined flight,
To Ghostty's realm or menu's door,
But Preferences stay as before!
With tests to guard each winding way,
The terminal commands dance and play! 🎹✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'tmux stuff' is vague and generic, using non-descriptive language that fails to convey meaningful information about the changeset's actual improvements. Use a more descriptive title that reflects the main change, such as 'Route terminal Command shortcuts to Ghostty with selection awareness' or 'Add Command key shortcut routing logic to terminal'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch cmux/tmux-bindings

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

Copy link

@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.

🧹 Nitpick comments (1)
cmuxTests/CmuxWebViewKeyEquivalentTests.swift (1)

2190-2207: Split the dual-assert test into separate test methods for sharper failures.

testRoutesOtherCommandShortcutsToTerminal currently validates two unrelated inputs. Splitting them makes failures more actionable during regressions.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmuxTests/CmuxWebViewKeyEquivalentTests.swift` around lines 2190 - 2207,
Split the dual-assert test testRoutesOtherCommandShortcutsToTerminal into two
distinct tests so each assertion fails independently: create one test (e.g.,
testRouteCommandOptionCToTerminal) that calls
shouldRouteTerminalCommandShortcutToGhostty(flags: [.command, .option], chars:
"c", keyCode: 8, terminalHasSelection: false) and asserts true, and a second
test (e.g., testRouteCommandVToTerminal) that calls
shouldRouteTerminalCommandShortcutToGhostty(flags: [.command], chars: "v",
keyCode: 9, terminalHasSelection: false) and asserts true; keep the same
parameters and expectations, just move each XCTAssertTrue into its own test
method to improve test failure granularity.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@cmuxTests/CmuxWebViewKeyEquivalentTests.swift`:
- Around line 2190-2207: Split the dual-assert test
testRoutesOtherCommandShortcutsToTerminal into two distinct tests so each
assertion fails independently: create one test (e.g.,
testRouteCommandOptionCToTerminal) that calls
shouldRouteTerminalCommandShortcutToGhostty(flags: [.command, .option], chars:
"c", keyCode: 8, terminalHasSelection: false) and asserts true, and a second
test (e.g., testRouteCommandVToTerminal) that calls
shouldRouteTerminalCommandShortcutToGhostty(flags: [.command], chars: "v",
keyCode: 9, terminalHasSelection: false) and asserts true; keep the same
parameters and expectations, just move each XCTAssertTrue into its own test
method to improve test failure granularity.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dba1e23 and 253c196.

📒 Files selected for processing (2)
  • Sources/AppDelegate.swift
  • cmuxTests/CmuxWebViewKeyEquivalentTests.swift
@greptile-apps
Copy link

greptile-apps bot commented Mar 1, 2026

Greptile Summary

This PR adds support for custom tmux prefixes using Command-based keyboard shortcuts. The implementation introduces a new routing function shouldRouteTerminalCommandShortcutToGhostty that forwards Command key combinations to the terminal when focused, enabling users to configure tmux with prefixes like Cmd+C.

Key changes:

  • Command shortcuts are now routed to the terminal to support custom tmux prefix bindings
  • Cmd+, (Preferences) is preserved for consistent macOS UX
  • Cmd+C with text selection is preserved for standard copy behavior
  • Critical app shortcuts (Cmd+Q, Cmd+N, Cmd+T, Cmd+W) are handled earlier in the event chain via handleCustomShortcut and remain unaffected
  • Comprehensive test coverage validates all edge cases and exceptions

The implementation follows existing patterns in the codebase (similar to shouldRouteTerminalFontZoomShortcutToGhostty) and balances advanced tmux user needs with essential app functionality.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The implementation is well-designed with appropriate safeguards for critical shortcuts, follows existing code patterns, includes comprehensive test coverage, and the changes are isolated to keyboard event routing logic
  • No files require special attention

Important Files Changed

Filename Overview
Sources/AppDelegate.swift Added shouldRouteTerminalCommandShortcutToGhostty function and integrated it into key event handling to support custom tmux prefixes with Command keys while preserving critical shortcuts
cmuxTests/CmuxWebViewKeyEquivalentTests.swift Added comprehensive test suite for the new Command shortcut routing function covering all edge cases and exceptions

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Key Event] --> B{Local Event Monitor<br/>`handleCustomShortcut`}
    B -->|Cmd+Q, Cmd+N, Cmd+T, Cmd+W<br/>handled| C[Event Consumed]
    B -->|Pass through| D{`performKeyEquivalent`}
    D --> E{Terminal focused?}
    E -->|No| F[Normal event handling]
    E -->|Yes| G{Font zoom shortcut?}
    G -->|Yes| H[Route to terminal]
    G -->|No| I{Browser event?}
    I -->|Yes| J[Handle browser event]
    I -->|No| K{**NEW: Command shortcut?**<br/>`shouldRouteTerminalCommand...`}
    K -->|Cmd+, or<br/>Cmd+C with selection| L{Main menu check}
    K -->|Other Cmd shortcuts| M[Route to terminal<br/>for tmux prefix]
    L -->|Consumed by menu| C
    L -->|Not consumed| F
Loading

Last reviewed commit: 253c196

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

Labels

None yet

1 participant