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()
|
M.toggle_panel()
|
||||||
elseif active_panel == 'interactive' then
|
elseif active_panel == 'interactive' then
|
||||||
M.toggle_interactive()
|
M.toggle_interactive()
|
||||||
|
elseif active_panel == 'stress' then
|
||||||
|
require('cp.stress').toggle()
|
||||||
else
|
else
|
||||||
logger.log(('Unknown panel type: %s'):format(tostring(active_panel)))
|
logger.log(('Unknown panel type: %s'):format(tostring(active_panel)))
|
||||||
end
|
end
|
||||||
|
|
@ -67,11 +69,11 @@ function M.toggle_interactive(interactor_cmd)
|
||||||
cache.load()
|
cache.load()
|
||||||
local contest_data = cache.get_contest_data(platform, contest_id)
|
local contest_data = cache.get_contest_data(platform, contest_id)
|
||||||
if
|
if
|
||||||
not contest_data
|
contest_data
|
||||||
or not contest_data.index_map
|
and contest_data.index_map
|
||||||
or not contest_data.problems[contest_data.index_map[problem_id]].interactive
|
and not contest_data.problems[contest_data.index_map[problem_id]].interactive
|
||||||
then
|
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
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -830,6 +832,7 @@ function M.toggle_panel(panel_opts)
|
||||||
local contest_data = cache.get_contest_data(platform, contest_id)
|
local contest_data = cache.get_contest_data(platform, contest_id)
|
||||||
if
|
if
|
||||||
contest_data
|
contest_data
|
||||||
|
and contest_data.index_map
|
||||||
and contest_data.problems[contest_data.index_map[state.get_problem_id()]].interactive
|
and contest_data.problems[contest_data.index_map[state.get_problem_id()]].interactive
|
||||||
then
|
then
|
||||||
logger.log('This is an interactive problem. Use :CP interact instead.', vim.log.levels.WARN)
|
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