feat(ui): auto-hide source buffer on close

This commit is contained in:
Barrett Ruth 2025-10-24 14:47:12 -04:00
parent 4b1b75fd6e
commit a842886933
4 changed files with 29 additions and 16 deletions

View file

@ -598,6 +598,10 @@ Output: |VerdictFormatResult| table with formatted line and optional highlights
{memory_limit_mb} (number) Memory limit in megabytes
{exit_code} (integer) Process exit code
{signal} (string|nil) Signal name for crashes (e.g. "SIGSEGV")
{time_actual_width} (integer|nil) Dynamic width for time value alignment
{time_limit_width} (integer|nil) Dynamic width for time limit alignment
{mem_actual_width} (integer|nil) Dynamic width for memory value alignment
{mem_limit_width} (integer|nil) Dynamic width for memory limit alignment
*VerdictFormatResult*
{line} (string) The formatted verdict line

View file

@ -58,7 +58,6 @@ function M.default_verdict_formatter(data)
local exit_str = data.signal and string.format('%d (%s)', data.exit_code, data.signal)
or tostring(data.exit_code)
-- Use dynamic widths if provided, otherwise use reasonable defaults
local time_actual_w = data.time_actual_width or 6
local time_limit_w = data.time_limit_width or 4
local mem_actual_w = data.mem_actual_width or 3

View file

@ -156,20 +156,15 @@ function M.toggle_edit(test_index)
local test_buffers = {}
local num_tests = #test_cases
-- Step 1: Create N columns (vsplit creates full-height columns)
for i = 1, num_tests - 1 do
vim.cmd('vsplit')
end
-- Step 2: Go to leftmost window
vim.cmd('1wincmd w')
-- Step 3: For each column, split horizontally into input (top) and expected (bottom)
for col = 1, num_tests do
-- Split current window horizontally
vim.cmd('split')
-- After split, cursor is in bottom window. Go up to input window.
vim.cmd('wincmd k')
local input_win = vim.api.nvim_get_current_win()
local input_buf = utils.create_buffer_with_options()
@ -180,7 +175,6 @@ function M.toggle_edit(test_index)
vim.bo[input_buf].buflisted = false
helpers.clearcol(input_buf)
-- Go down to expected window
vim.cmd('wincmd j')
local expected_win = vim.api.nvim_get_current_win()
local expected_buf = utils.create_buffer_with_options()
@ -198,7 +192,6 @@ function M.toggle_edit(test_index)
expected_win = expected_win,
}
-- Move to next column (go up to top, then right)
vim.cmd('wincmd k')
vim.cmd('wincmd l')
end

View file

@ -247,6 +247,23 @@ function M.ensure_io_view()
current_test_index = 1,
})
local source_buf = vim.api.nvim_win_get_buf(solution_win)
vim.api.nvim_create_autocmd('BufDelete', {
buffer = source_buf,
callback = function()
local io = state.get_io_view_state()
if io then
if io.output_buf and vim.api.nvim_buf_is_valid(io.output_buf) then
vim.api.nvim_buf_delete(io.output_buf, { force = true })
end
if io.input_buf and vim.api.nvim_buf_is_valid(io.input_buf) then
vim.api.nvim_buf_delete(io.input_buf, { force = true })
end
state.set_io_view_state(nil)
end
end,
})
if cfg.hooks and cfg.hooks.setup_io_output then
pcall(cfg.hooks.setup_io_output, output_buf, state)
end