From b3014e9c86c4ffc5f459ff5e0dd19e80b08d2277 Mon Sep 17 00:00:00 2001 From: Barrett Ruth <62671086+barrettruth@users.noreply.github.com> Date: Thu, 5 Mar 2026 15:31:47 -0500 Subject: [PATCH] fix(setup): clear output buffer when switching contests (#313) ## Problem `setup_problem` only cleared the output buffer when `old_problem_id ~= problem_id`. If two different contests share a problem with the same ID (e.g. both have `a`), the condition is false and stale output from the previous contest remains visible. ## Solution Clear the output buffer at the top of `proceed()` in `setup_contest` whenever `is_new_contest` is true, before any problem setup runs. Closes #303. --- 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)