fix(cli): apply focus to tmux pane for external sessions#307
Draft
sei40kr wants to merge 1 commit intofolke:mainfrom
Draft
fix(cli): apply focus to tmux pane for external sessions#307sei40kr wants to merge 1 commit intofolke:mainfrom
sei40kr wants to merge 1 commit intofolke:mainfrom
Conversation
ef2ada6 to
54125df
Compare
Adds `Session:focus()`, `Session:is_focused()`, and `Session:blur()` backend hooks with tmux implementations, and unifies the UI layer to dispatch through `state.session:*`. `Terminal` is already a `Session` backend so `state.terminal === state.session` for terminal-backed sessions — the same calls cover both paths. tmux: - focus: select-window then select-pane (window switch handles create="window", select-pane handles the pane within the window) - is_focused: compare client_active_pane with the pane id - blur: switch back to the editor pane via $TMUX_PANE 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
cli.toggle({ focus = true })andcli.focus()did not focus the tmux pane when using external mux sessions (cli.mux.enabled = truewithcreate = "split"/"window").Root cause
sidekick.cliwas built aroundstate.terminal(nvim's embedded terminal). When external mux sessions were added, the UI layer (M.toggle/M.focus) still keyed offstate.terminal, andSessionhad nofocus()method — so there was literally no path from the UI totmux select-pane. Terminal focus kept working only becausenvim_set_current_winis a synchronous API the UI callback could call directly via a capturedopts.focus, bypassing the missing propagation.Changes
focus,is_focused, andblurtoSessioncontract (empty /falsedefaults on the base for backends that don't support them)focus:tmux select-windowthentmux select-pane—select-windowfirst socreate = "window"switches the client to the pane's window (no-op forcreate = "split")is_focused:tmux display-messagecomparing#{client_active_pane}with the pane idblur: switch back to the editor pane identified via$TMUX_PANE(the env var tmux sets for the pane nvim is running in) — works regardless of tmux historystate.session:*.Terminalis already registered as aSessionbackend (state.terminal === state.sessionfor terminal-backed sessions), so the same calls work for both paths:Terminal:focus()/:is_focused()/:blur()(existing methods)Tmux:focus()/:is_focused()/:blur()(new)M.attachnow fires focus onopts.show and opts.focus ~= falsefor both backends, fixing the silent default-false asymmetry external previously had against terminalM.togglecallback handles both backends viastate.session:focus(), keeping the existingis_open()gate so toggling terminal visibility off doesn't immediately re-open itM.focuscallback usesstate.session:is_focused()/:blur()/:focus()directly — the toggle-focus behavior now applies to external panes too (when invoked from inside the pane, e.g. via a tmux keybinding that calls back into nvim)Behavior matrix after the fix
toggle()toggle({ focus = true })toggle({ focus = false })send("x")send("x", { focus = false })focus()from editorfocus()from inside the pane$TMUX_PANE)hide()close()Related Issue(s)
focusis not appplied with tmux pane #179Screenshots
N/A — behavioral fix with no UI change.
🤖 Generated with Claude Code