Skip to content

fix(cli): apply focus to tmux pane for external sessions#307

Draft
sei40kr wants to merge 1 commit intofolke:mainfrom
sei40kr:fix-179
Draft

fix(cli): apply focus to tmux pane for external sessions#307
sei40kr wants to merge 1 commit intofolke:mainfrom
sei40kr:fix-179

Conversation

@sei40kr
Copy link
Copy Markdown

@sei40kr sei40kr commented Apr 20, 2026

Description

cli.toggle({ focus = true }) and cli.focus() did not focus the tmux pane when using external mux sessions (cli.mux.enabled = true with create = "split" / "window").

Root cause

sidekick.cli was built around state.terminal (nvim's embedded terminal). When external mux sessions were added, the UI layer (M.toggle / M.focus) still keyed off state.terminal, and Session had no focus() method — so there was literally no path from the UI to tmux select-pane. Terminal focus kept working only because nvim_set_current_win is a synchronous API the UI callback could call directly via a captured opts.focus, bypassing the missing propagation.

Changes

  • Add Session:focus() hook on the backend base class (empty stub for backends that don't support it)
  • Implement focus() on the tmux backend via tmux select-window + tmux select-paneselect-window first so create = "window" actually switches the client to the pane's window (a no-op for create = "split" where the pane already lives in the current window)
  • Unify the UI layer through state.session:focus(). Terminal is already registered as a Session backend (state.terminal === state.session for terminal-backed sessions), so the same call works for both paths:
    • terminal-backed session → Terminal:focus() (existing: show() + nvim_set_current_win)
    • external tmux session → Tmux:focus() (new: tmux select-window + tmux select-pane)
  • M.attach now fires focus on opts.show and opts.focus ~= false for both backends, fixing the silent default-false asymmetry external previously had against terminal
  • M.toggle callback handles both backends via state.session:focus(), keeping the existing is_open() gate so toggling terminal visibility off doesn't immediately re-open it
  • M.focus callback routes to state.terminal:blur() when terminal is focused (existing behavior), otherwise state.session:focus() for both backends

Behavior matrix after the fix

Call terminal external tmux
toggle() toggle visibility + focus focus pane
toggle({ focus = true }) toggle visibility + focus focus pane
toggle({ focus = false }) toggle visibility only no-op
send("x") show + focus, then send focus pane, then send
send("x", { focus = false }) show, then send send only
focus() toggle focus (blur if focused) focus pane
hide() hide window no-op (filter excludes external)
close() close terminal detach tracking (pane stays)

Related Issue(s)

Screenshots

N/A — behavioral fix with no UI change.

🤖 Generated with Claude Code

@github-actions github-actions Bot added the size/m Medium PR (<50 lines changed) label Apr 20, 2026
@sei40kr sei40kr force-pushed the fix-179 branch 3 times, most recently from aff101b to ef2ada6 Compare April 20, 2026 08:06
Adds `Session:focus()` backend hook with a tmux implementation via
`tmux select-pane`, and unifies the UI layer to dispatch through
`state.session:focus()`. `Terminal` is already a `Session` backend so
`state.terminal === state.session` for terminal-backed sessions — the
same call covers both paths.

Also fixes the default-focus asymmetry in `M.attach`: external focus
now fires on `opts.show and opts.focus ~= false` to match terminal,
so `send()` and `toggle()` (no args) focus external panes the same
way they focus terminals.

Closes folke#179.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added size/l Large PR (<100 lines changed) and removed size/m Medium PR (<50 lines changed) labels Apr 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/l Large PR (<100 lines changed)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: focus is not appplied with tmux pane

1 participant