From a67e0d5db8de3e1abc52f0b7262f2f9bd614da32 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Thu, 5 Mar 2026 15:27:48 -0500 Subject: [PATCH] fix(setup): clear output buffer when switching contests Problem: `setup_problem` only cleared the output buffer when `old_problem_id ~= problem_id`. If two different contests both had a problem with the same ID (e.g. `a`), the condition was false and stale output from the previous contest remained visible. Solution: clear the output buffer at the top of `proceed()` whenever `is_new_contest` is true, before any problem setup runs. --- lua/cp/setup.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lua/cp/setup.lua b/lua/cp/setup.lua index eb7ba8c..7a33cd0 100644 --- a/lua/cp/setup.lua +++ b/lua/cp/setup.lua @@ -182,6 +182,12 @@ function M.setup_contest(platform, contest_id, problem_id, language) cache.load() local function proceed(contest_data) + if is_new_contest then + local io_state = state.get_io_view_state() + if io_state and io_state.output_buf and vim.api.nvim_buf_is_valid(io_state.output_buf) then + require('cp.utils').update_buffer_content(io_state.output_buf, {}, nil, nil) + end + end local problems = contest_data.problems local pid = problem_id and problem_id or problems[1].id M.setup_problem(pid, language)