fix(open_url): open problem URL when switching problems

Also fix contest-change detection so URL open logic triggers when either platform or contest changes. This makes :CP next/:CP prev and problem jumps open the correct page when open_url is enabled.

Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
Harivansh Rathi 2026-02-22 20:44:40 -05:00 committed by Barrett Ruth
parent d3ac300ea0
commit 1c31abe3d6
2 changed files with 6 additions and 3 deletions

View file

@ -121,6 +121,7 @@ end
---@param language? string
function M.setup_contest(platform, contest_id, problem_id, language)
local old_platform, old_contest_id = state.get_platform(), state.get_contest_id()
local old_problem_id = state.get_problem_id()
state.set_platform(platform)
state.set_contest_id(contest_id)
@ -133,7 +134,7 @@ function M.setup_contest(platform, contest_id, problem_id, language)
end
end
local is_new_contest = old_platform ~= platform and old_contest_id ~= contest_id
local is_new_contest = old_platform ~= platform or old_contest_id ~= contest_id
cache.load()
@ -143,7 +144,9 @@ function M.setup_contest(platform, contest_id, problem_id, language)
M.setup_problem(pid, language)
start_tests(platform, contest_id, problems)
if config_module.get_config().open_url and is_new_contest and contest_data.url then
local is_new_problem = old_problem_id ~= pid
local should_open_url = config_module.get_config().open_url and (is_new_contest or is_new_problem)
if should_open_url and contest_data.url then
vim.ui.open(contest_data.url:format(pid))
end
end