Skip to content

Commit

Permalink
fix(toc): open new win from toc when neorg win was closed
Browse files Browse the repository at this point in the history
  • Loading branch information
benlubas authored and vhyrro committed Jun 25, 2024
1 parent b0544ed commit c2d58da
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lua/neorg/modules/core/qol/toc/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,21 @@ module.public = {
end

local norg_window = vim.fn.bufwinid(norg_buffer)
vim.api.nvim_set_current_win(norg_window)
vim.api.nvim_set_current_buf(norg_buffer)
if norg_window == -1 then
local toc_window = vim.fn.bufwinid(ui_data.buffer)
local buf_width = nil
if toc_window ~= -1 then
buf_width = vim.api.nvim_win_get_width(toc_window) - module.private.get_toc_width(ui_data)
if buf_width < 1 then
buf_width = nil
end
end
norg_window =
vim.api.nvim_open_win(norg_buffer, true, { win = 0, vertical = true, width = buf_width })
else
vim.api.nvim_set_current_win(norg_window)
vim.api.nvim_set_current_buf(norg_buffer)
end
vim.api.nvim_win_set_cursor(norg_window, { location[1] + 1, location[2] })

if module.config.public.close_after_use then
Expand Down

0 comments on commit c2d58da

Please sign in to comment.