Skip to content

Commit ba93a3a

Browse files
fix: restore proper window layout after diff operations
1 parent 24c1f43 commit ba93a3a

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

lua/claudecode/diff.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,14 @@ local function is_buffer_dirty(file_path)
111111
return is_dirty, nil
112112
end
113113

114+
---Restore window layout by delegating to terminal module
115+
local function restore_window_layout()
116+
local ok, terminal = pcall(require, "claudecode.terminal")
117+
if ok and terminal.restore_window_layout then
118+
terminal.restore_window_layout()
119+
end
120+
end
121+
114122
---Setup the diff module
115123
---@param user_config table? The configuration passed from init.lua
116124
function M.setup(user_config)
@@ -369,6 +377,8 @@ function M._resolve_diff_as_saved(tab_name, buffer_id)
369377
if diff_data.target_window and vim.api.nvim_win_is_valid(diff_data.target_window) then
370378
vim.api.nvim_set_current_win(diff_data.target_window)
371379
vim.cmd("diffoff")
380+
-- Restore proper window layout after closing diff
381+
restore_window_layout()
372382
end
373383

374384
-- Create MCP-compliant response
@@ -678,6 +688,8 @@ function M._cleanup_diff_state(tab_name, reason)
678688
vim.api.nvim_win_call(diff_data.target_window, function()
679689
vim.cmd("diffoff")
680690
end)
691+
-- Restore proper window layout after cleanup
692+
restore_window_layout()
681693
end
682694

683695
-- Remove from active diffs
@@ -1016,6 +1028,8 @@ function M.deny_current_diff()
10161028
if target_window and vim.api.nvim_win_is_valid(target_window) then
10171029
vim.api.nvim_set_current_win(target_window)
10181030
vim.cmd("diffoff")
1031+
-- Restore proper window layout after rejecting diff
1032+
restore_window_layout()
10191033
end
10201034

10211035
M._resolve_diff_as_rejected(tab_name)

lua/claudecode/terminal.lua

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,4 +423,29 @@ function M._get_managed_terminal_for_test()
423423
return nil
424424
end
425425

426+
---Restore window layout after closing diff windows
427+
-- This ensures that Claude's terminal maintains its configured size ratio
428+
function M.restore_window_layout()
429+
local logger = require("claudecode.logger")
430+
local effective_config = build_config({})
431+
432+
-- Get active terminal buffer number
433+
local terminal_bufnr = M.get_active_terminal_bufnr()
434+
if not terminal_bufnr then
435+
return
436+
end
437+
438+
-- Check if terminal is visible and get its window
439+
if is_terminal_visible(terminal_bufnr) then
440+
local bufinfo = vim.fn.getbufinfo(terminal_bufnr)
441+
if bufinfo and #bufinfo > 0 and #bufinfo[1].windows > 0 then
442+
local terminal_win = bufinfo[1].windows[1]
443+
local total_width = vim.o.columns
444+
local terminal_width = math.floor(total_width * effective_config.split_width_percentage)
445+
vim.api.nvim_win_set_width(terminal_win, terminal_width)
446+
logger.debug("terminal", "Restored window layout with terminal width:", terminal_width)
447+
end
448+
end
449+
end
450+
426451
return M

0 commit comments

Comments
 (0)