fix: cancel active process on contest switch
Problem: switching contests while a run, interactive session, or stress test was in progress left orphaned callbacks and terminal jobs alive. Running `:CP run` twice also allowed the first run's stale output to overwrite the buffer after the second run completed. Solution: replace the `io_view_running` bool in `views.lua` with a generation counter (`_run_gen`); each `run_io_view` call increments it and captures a local `gen`, and async callbacks bail out early when `gen ~= _run_gen`. Add `cancel_io_view`, `cancel_interactive` to `views.lua` and `cancel` to `stress.lua` for forceful teardown without layout restore. Call these in `setup_contest` whenever `is_new_contest` is true.
This commit is contained in:
parent
b3014e9c86
commit
9f23076420
3 changed files with 57 additions and 18 deletions
|
|
@ -232,4 +232,18 @@ function M.toggle(generator_cmd, brute_cmd)
|
|||
end)
|
||||
end
|
||||
|
||||
function M.cancel()
|
||||
if state.stress_buf and vim.api.nvim_buf_is_valid(state.stress_buf) then
|
||||
local job = vim.b[state.stress_buf].terminal_job_id
|
||||
if job then
|
||||
vim.fn.jobstop(job)
|
||||
end
|
||||
end
|
||||
if state.saved_stress_session then
|
||||
vim.fn.delete(state.saved_stress_session)
|
||||
state.saved_stress_session = nil
|
||||
end
|
||||
state.set_active_panel(nil)
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue