[BUG] ClaudeCodeSend leaves source buffer in insert mode (snacks provider, focus_after_send off)

Offen
#423 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
50/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
vim
Bereich
devtools

Rechercherichtung

Start with send_at_mention in init.lua, which calls terminal.ensure_visible() after a successful send, then follow the fallback to ensure_terminal_visible_no_focus in terminal.lua for the snacks provider. Check whether the snacks buffer-local auto_insert BufEnter autocmd leaves a pending startinsert after the terminal is shown without focus. Done means the source window stays in its current mode after :ClaudeCodeSend when focus_after_send is off, with no change to focus-on behaviour.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

needs-triage

Describe the bug

With the snacks provider and focus_after_send off (the default), sending a visual selection with :ClaudeCodeSend leaves the source buffer in insert mode. Focus is correctly kept on the source window, but Neovim is in insert mode there, so the next keystrokes are typed into the buffer.

To reproduce

  1. Use the snacks terminal provider with default terminal.auto_insert and focus_after_send = false.
  2. Start Claude, then hide the terminal.
  3. In a normal file, select text in visual mode and run :ClaudeCodeSend (mapped as <cmd>ClaudeCodeSend<cr> in visual mode).
  4. The terminal is shown again and focus returns to the source window, which is now in insert mode.

Expected

Focus and mode of the source window are unchanged when focus_after_send is off.

Likely cause (not fully verified)

init.lua send_at_mention calls terminal.ensure_visible() after a successful send. The snacks provider has no ensure_visible, so terminal.lua falls back to ensure_terminal_visible_no_focus, which opens or shows the terminal. Entering the terminal buffer appears to trigger snacks' buffer-local auto_insert BufEnter autocmd, which runs startinsert. Focus then moves back to the source window, but the pending insert carries over. I did not trace which exact call triggers it.

Workaround

A User ClaudeCodeSendComplete autocmd that cancels the insert:

vim.api.nvim_create_autocmd("User", {
  pattern = "ClaudeCodeSendComplete",
  callback = function()
    local function fix()
      if vim.bo.buftype ~= "terminal" then
        vim.cmd("stopinsert")
      end
    end
    fix()
    vim.schedule(fix)
  end,
})

Setting terminal.auto_insert = false also avoids it, but then focusing Claude no longer enters insert mode.

Suggested fix

When ensure_visible opens or shows the terminal without focus, do not leave a pending startinsert. For example, run the show with snacks auto_insert/start_insert disabled, or call stopinsert when the current window is not the terminal after showing it.

Related

#145 and #232 cover focusing the terminal. This one is about the unfocused path.

Vorherrschende Sprache
Lua
Sterne
3.1k
Forks
223
Ø Merge
6 Std. 47 Min.
Gemergte PRs (30 T.)
93

Entwicklungsumgebung

In Codespaces öffnen

Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.

  • Kein Dockerfile und keine Docker-Compose-Datei
  • Keine Pull-Request-Vorlage
  • Kein Beitragsleitfaden

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus coder/claudecode.nvim

Alle Issues in coder/claudecode.nvim

Ähnliche Issues

Weitere Issues zu Lua

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.