Skip to content

Commit 122fa97

Browse files
committed
refactor: improve terminal toggle logic
1 parent 183cebb commit 122fa97

File tree

2 files changed

+5
-16
lines changed

2 files changed

+5
-16
lines changed

lua/claudecode/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ function M._create_commands()
299299
if current_mode == "v" or current_mode == "V" or current_mode == "\22" then -- \22 is CTRL-V (blockwise visual mode)
300300
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<Esc>", true, false, true), "n", false)
301301
end
302-
terminal.toggle_fallback_terminal() -- `opts.fargs` can be used for future enhancements.
302+
terminal.toggle({}) -- `opts.fargs` can be used for future enhancements.
303303
end, {
304304
nargs = "?",
305305
desc = "Toggle the Claude Code terminal window",

lua/claudecode/terminal.lua

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -516,9 +516,10 @@ function M.toggle(opts_override)
516516
local current_neovim_win_id = vim.api.nvim_get_current_win()
517517

518518
if claude_term_neovim_win_id == current_neovim_win_id then
519-
close_fallback_terminal()
519+
vim.api.nvim_win_hide(claude_term_neovim_win_id)
520520
else
521-
focus_fallback_terminal() -- This already calls startinsert
521+
vim.api.nvim_set_current_win(claude_term_neovim_win_id)
522+
vim.cmd("startinsert")
522523
end
523524
else
524525
-- Check if there's an existing Claude terminal we lost track of
@@ -532,7 +533,7 @@ function M.toggle(opts_override)
532533
-- Check if we're currently in this terminal
533534
local current_neovim_win_id = vim.api.nvim_get_current_win()
534535
if existing_win == current_neovim_win_id then
535-
close_fallback_terminal()
536+
vim.api.nvim_win_hide(existing_win)
536537
else
537538
focus_fallback_terminal()
538539
end
@@ -572,15 +573,3 @@ end
572573

573574
return M
574575

575-
--- Toggles the Claude terminal window.
576-
-- If the terminal is already open, it brings it to focus.
577-
-- If it's not open, it creates a new terminal.
578-
function M.toggle_fallback_terminal()
579-
if is_fallback_terminal_valid() then
580-
vim.api.nvim_set_current_win(managed_fallback_terminal_winid)
581-
else
582-
local cmd_string = get_claude_command()
583-
local env_table = { CLAUDE_TERMINAL_MODE = "true" }
584-
open_fallback_terminal(cmd_string, env_table, term_module_config)
585-
end
586-
end

0 commit comments

Comments
 (0)