diff --git a/doc/cp.nvim.txt b/doc/cp.nvim.txt index e85ea45..49cdaf7 100644 --- a/doc/cp.nvim.txt +++ b/doc/cp.nvim.txt @@ -143,7 +143,7 @@ run CSES problems with Rust using the single schema: (default: concatenates contest_id and problem_id, lowercased) {ui} (|CpUI|) UI settings: panel, diff backend, picker. {open_url} (boolean) Open the contest & problem url in the browser - when the contest is first opened. + when a new contest is opened or the active problem changes. *CpPlatform* Fields: ~ diff --git a/lua/cp/setup.lua b/lua/cp/setup.lua index e3bb38d..deeadd9 100644 --- a/lua/cp/setup.lua +++ b/lua/cp/setup.lua @@ -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