Skip to content

Commit 606c747

Browse files
fix(capture): Close capture window only if it's active
1 parent 71ac9d3 commit 606c747

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

lua/orgmode/utils/init.lua

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ function utils.open_tmp_org_window(height, split_mode, border, on_close)
415415
utils.open_window(vim.fn.tempname() .. '.org', height or 16, split_mode, border)
416416
vim.cmd([[setf org]])
417417
vim.cmd([[setlocal bufhidden=wipe nobuflisted nolist noswapfile nofoldenable]])
418+
local bufnr = vim.api.nvim_get_current_buf()
418419

419420
if on_close then
420421
vim.api.nvim_create_autocmd('BufWipeout', {
@@ -431,13 +432,19 @@ function utils.open_tmp_org_window(height, split_mode, border, on_close)
431432
})
432433
end
433434

434-
return function()
435-
vim.api.nvim_create_augroup('OrgTmpWindow', { clear = true })
435+
local close_win = function()
436+
if vim.api.nvim_get_current_buf() ~= bufnr then
437+
return
438+
end
436439
if #vim.api.nvim_list_wins() == 1 then
437-
vim.cmd('q!')
438-
else
439-
pcall(vim.api.nvim_win_close, 0, true)
440+
return vim.cmd('q!')
440441
end
442+
return pcall(vim.api.nvim_win_close, 0, true)
443+
end
444+
445+
return function()
446+
vim.api.nvim_create_augroup('OrgTmpWindow', { clear = true })
447+
close_win()
441448
if prev_winnr and vim.api.nvim_win_is_valid(prev_winnr) then
442449
vim.api.nvim_set_current_win(prev_winnr)
443450
end

0 commit comments

Comments
 (0)