outline: Prevent buffer taking the whole space when closing another buffer
Major thanks to https://github.com/kyazdani42/nvim-tree.lua
This commit is contained in:
@@ -20,7 +20,8 @@ end
|
|||||||
|
|
||||||
local function setup_autocmd()
|
local function setup_autocmd()
|
||||||
vim.cmd(
|
vim.cmd(
|
||||||
"autocmd InsertLeave,BufEnter,BufWinEnter,TabEnter,BufWritePost * :lua require('symbols-outline')._refresh()")
|
"au InsertLeave,BufEnter,BufWinEnter,TabEnter,BufWritePost * :lua require('symbols-outline')._refresh()")
|
||||||
|
vim.cmd "au BufDelete * lua require'symbols-outline'._prevent_buffer_override()"
|
||||||
if D.opts.highlight_hovered_item then
|
if D.opts.highlight_hovered_item then
|
||||||
vim.cmd(
|
vim.cmd(
|
||||||
"autocmd CursorHold * :lua require('symbols-outline')._highlight_current_item()")
|
"autocmd CursorHold * :lua require('symbols-outline')._highlight_current_item()")
|
||||||
@@ -277,6 +278,33 @@ function D._highlight_current_item()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- credits: https://github.com/kyazdani42/nvim-tree.lua
|
||||||
|
function D._prevent_buffer_override()
|
||||||
|
vim.schedule(function()
|
||||||
|
local curwin = vim.api.nvim_get_current_win()
|
||||||
|
local curbuf = vim.api.nvim_win_get_buf(curwin)
|
||||||
|
local wins = vim.api.nvim_list_wins()
|
||||||
|
|
||||||
|
if curwin ~= D.state.outline_win or curbuf ~= D.state.outline_buf then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
vim.cmd("buffer " .. D.state.outline_buf)
|
||||||
|
|
||||||
|
local current_win_width = vim.api.nvim_win_get_width(curwin)
|
||||||
|
if #wins < 2 then
|
||||||
|
vim.cmd("vsplit")
|
||||||
|
vim.cmd("vertical resize " .. math.ceil(current_win_width * 0.75))
|
||||||
|
else
|
||||||
|
vim.cmd("wincmd l")
|
||||||
|
end
|
||||||
|
|
||||||
|
vim.cmd("buffer " .. curbuf)
|
||||||
|
vim.cmd("bnext")
|
||||||
|
vim.cmd("wincmd r")
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
local function setup_keymaps(bufnr)
|
local function setup_keymaps(bufnr)
|
||||||
-- goto_location of symbol
|
-- goto_location of symbol
|
||||||
vim.api.nvim_buf_set_keymap(bufnr, "n", "<Cr>",
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "<Cr>",
|
||||||
|
|||||||
Reference in New Issue
Block a user