Skip to content

refactor: improve terminal toggle logic #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions lua/claudecode/terminal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ local function open_fallback_terminal(cmd_string, env_table, effective_term_conf

managed_fallback_terminal_winid = new_winid
managed_fallback_terminal_bufnr = vim.api.nvim_get_current_buf()
vim.bo[managed_fallback_terminal_bufnr].bufhidden = "wipe" -- Wipe buffer when hidden (e.g., window closed)
vim.bo[managed_fallback_terminal_bufnr].bufhidden = "hide" -- Hide buffer when hidden (e.g., window closed)
-- buftype=terminal is set by termopen

vim.api.nvim_set_current_win(managed_fallback_terminal_winid)
Expand Down Expand Up @@ -516,9 +516,10 @@ function M.toggle(opts_override)
local current_neovim_win_id = vim.api.nvim_get_current_win()

if claude_term_neovim_win_id == current_neovim_win_id then
close_fallback_terminal()
vim.api.nvim_win_hide(claude_term_neovim_win_id)
else
focus_fallback_terminal() -- This already calls startinsert
vim.api.nvim_set_current_win(claude_term_neovim_win_id)
vim.cmd("startinsert")
end
else
-- Check if there's an existing Claude terminal we lost track of
Expand All @@ -532,7 +533,7 @@ function M.toggle(opts_override)
-- Check if we're currently in this terminal
local current_neovim_win_id = vim.api.nvim_get_current_win()
if existing_win == current_neovim_win_id then
close_fallback_terminal()
vim.api.nvim_win_hide(existing_win)
else
focus_fallback_terminal()
end
Expand Down