fix(views): fix interactive guard logic and add stress panel support
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.
This commit is contained in:
parent
bfa2cf893c
commit
ad90d564ca
1 changed files with 7 additions and 4 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue