From ad90d564ca8fe735e69a578234c805a947d711d3 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Tue, 3 Mar 2026 14:52:17 -0500 Subject: [PATCH] fix(views): fix interactive guard logic and add stress panel support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: toggle_interactive() had its condition inverted — it blocked :CP interact on non-interactive problems while showing the message "This problem is interactive", and passed through on interactive ones. The panel guard in toggle_panel() was also missing a nil-check on contest_data.index_map, which could crash if the index map was absent. Solution: invert the toggle_interactive() guard to match the symmetrical pattern in toggle_view(), fix the error message to say "not interactive", and add the missing index_map guard. Also handle the stress panel type in M.disable() so :CP stress can be toggled off. --- lua/cp/ui/views.lua | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lua/cp/ui/views.lua b/lua/cp/ui/views.lua index c2c1c31..041200e 100644 --- a/lua/cp/ui/views.lua +++ b/lua/cp/ui/views.lua @@ -26,6 +26,8 @@ function M.disable() M.toggle_panel() elseif active_panel == 'interactive' then M.toggle_interactive() + elseif active_panel == 'stress' then + require('cp.stress').toggle() else logger.log(('Unknown panel type: %s'):format(tostring(active_panel))) end @@ -67,11 +69,11 @@ function M.toggle_interactive(interactor_cmd) cache.load() local contest_data = cache.get_contest_data(platform, contest_id) if - not contest_data - or not contest_data.index_map - or not contest_data.problems[contest_data.index_map[problem_id]].interactive + contest_data + and contest_data.index_map + and not contest_data.problems[contest_data.index_map[problem_id]].interactive then - logger.log('This problem is interactive. Use :CP interact.', vim.log.levels.ERROR) + logger.log('This problem is not interactive. Use :CP {run,panel}.', vim.log.levels.ERROR) return end @@ -830,6 +832,7 @@ function M.toggle_panel(panel_opts) local contest_data = cache.get_contest_data(platform, contest_id) if contest_data + and contest_data.index_map and contest_data.problems[contest_data.index_map[state.get_problem_id()]].interactive then logger.log('This is an interactive problem. Use :CP interact instead.', vim.log.levels.WARN)