Merge pull request #160 from barrett-ruth/feat/window-state
add solution window to state
This commit is contained in:
commit
52a4286b70
2 changed files with 16 additions and 0 deletions
|
|
@ -172,6 +172,7 @@ function M.setup_problem(problem_id, language)
|
||||||
vim.api.nvim_buf_set_name(prov.bufnr, source_file)
|
vim.api.nvim_buf_set_name(prov.bufnr, source_file)
|
||||||
vim.bo[prov.bufnr].swapfile = true
|
vim.bo[prov.bufnr].swapfile = true
|
||||||
vim.cmd(string.format('silent keepalt noautocmd write! %s', vim.fn.fnameescape(source_file)))
|
vim.cmd(string.format('silent keepalt noautocmd write! %s', vim.fn.fnameescape(source_file)))
|
||||||
|
state.set_solution_win(vim.api.nvim_get_current_win())
|
||||||
if config.hooks and config.hooks.setup_code and not vim.b[prov.bufnr].cp_setup_done then
|
if config.hooks and config.hooks.setup_code and not vim.b[prov.bufnr].cp_setup_done then
|
||||||
local ok = pcall(config.hooks.setup_code, state)
|
local ok = pcall(config.hooks.setup_code, state)
|
||||||
if ok then
|
if ok then
|
||||||
|
|
@ -194,6 +195,7 @@ function M.setup_problem(problem_id, language)
|
||||||
vim.cmd.only({ mods = { silent = true } })
|
vim.cmd.only({ mods = { silent = true } })
|
||||||
vim.cmd.e(source_file)
|
vim.cmd.e(source_file)
|
||||||
local bufnr = vim.api.nvim_get_current_buf()
|
local bufnr = vim.api.nvim_get_current_buf()
|
||||||
|
state.set_solution_win(vim.api.nvim_get_current_win())
|
||||||
if config.hooks and config.hooks.setup_code and not vim.b[bufnr].cp_setup_done then
|
if config.hooks and config.hooks.setup_code and not vim.b[bufnr].cp_setup_done then
|
||||||
local ok = pcall(config.hooks.setup_code, state)
|
local ok = pcall(config.hooks.setup_code, state)
|
||||||
if ok then
|
if ok then
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ local state = {
|
||||||
saved_session = nil,
|
saved_session = nil,
|
||||||
active_panel = nil,
|
active_panel = nil,
|
||||||
provisional = nil,
|
provisional = nil,
|
||||||
|
solution_win = nil,
|
||||||
}
|
}
|
||||||
|
|
||||||
---@return string|nil
|
---@return string|nil
|
||||||
|
|
@ -153,6 +154,19 @@ function M.set_provisional(p)
|
||||||
state.provisional = p
|
state.provisional = p
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@return integer?
|
||||||
|
function M.get_solution_win()
|
||||||
|
if state.solution_win and vim.api.nvim_win_is_valid(state.solution_win) then
|
||||||
|
return state.solution_win
|
||||||
|
end
|
||||||
|
return vim.api.nvim_get_current_win()
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param win integer?
|
||||||
|
function M.set_solution_win(win)
|
||||||
|
state.solution_win = win
|
||||||
|
end
|
||||||
|
|
||||||
M._state = state
|
M._state = state
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue