Skip to content

Commit

Permalink
open tmp window: handle case where tmp window is prev window
Browse files Browse the repository at this point in the history
  • Loading branch information
Maltimore committed Jan 16, 2023
1 parent dadf563 commit b05d0a3
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lua/orgmode/utils/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -536,10 +536,12 @@ end

function utils.open_tmp_org_window(height, split_mode, on_close)
local winnr = vim.api.nvim_get_current_win()
local bufnr = vim.api.nvim_get_current_buf()
utils.open_window(vim.fn.tempname(), height or 16, split_mode)
vim.cmd([[setf org]])
vim.cmd([[setlocal bufhidden=wipe nobuflisted nolist noswapfile nofoldenable]])
vim.api.nvim_buf_set_var(0, 'org_prev_window', winnr)
vim.api.nvim_buf_set_var(0, 'org_prev_buffer', bufnr)

if on_close then
vim.api.nvim_create_autocmd('BufWipeout', {
Expand All @@ -559,9 +561,14 @@ function utils.open_tmp_org_window(height, split_mode, on_close)
return function()
vim.api.nvim_create_augroup('OrgTmpWindow', { clear = true })
local prev_winnr = vim.api.nvim_buf_get_var(0, 'org_prev_window')
vim.api.nvim_win_close(0, true)
if prev_winnr and vim.api.nvim_win_is_valid(prev_winnr) then
vim.api.nvim_set_current_win(prev_winnr)
if prev_winnr ~= vim.api.nvim_get_current_win() then
vim.api.nvim_win_close(0, true)
if prev_winnr and vim.api.nvim_win_is_valid(prev_winnr) then
vim.api.nvim_set_current_win(prev_winnr)
end
else
local prev_bufnr = vim.api.nvim_buf_get_var(0, 'org_prev_buffer')
vim.api.nvim_set_current_buf(prev_bufnr)
end
end
end
Expand Down

0 comments on commit b05d0a3

Please sign in to comment.