feat: add command to prevent nvim-tree window override by another buffer
This commit is contained in:
@@ -186,6 +186,10 @@ This plugin is very fast because it uses the `libuv` `scandir` and `scandir_next
|
|||||||
- Mouse support
|
- Mouse support
|
||||||
- It's fast
|
- It's fast
|
||||||
|
|
||||||
|
## Tips
|
||||||
|
|
||||||
|
- You can edit the size of the tree during runtime with `:lua require'nvim-tree.view'.View.width = 50`
|
||||||
|
|
||||||
## Screenshots
|
## Screenshots
|
||||||
|
|
||||||

|

|
||||||
|
|||||||
@@ -260,12 +260,12 @@ function M.open_file(mode, filename)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
view.resize()
|
|
||||||
|
|
||||||
if vim.g.nvim_tree_quit_on_open == 1 and mode ~= 'preview' then
|
if vim.g.nvim_tree_quit_on_open == 1 and mode ~= 'preview' then
|
||||||
view.close()
|
view.close()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
view.resize()
|
||||||
|
|
||||||
renderer.draw(M.Tree, true)
|
renderer.draw(M.Tree, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ M.View = {
|
|||||||
winnr = nil,
|
winnr = nil,
|
||||||
width = 30,
|
width = 30,
|
||||||
side = 'left',
|
side = 'left',
|
||||||
auto_resize = false,
|
|
||||||
winopts = {
|
winopts = {
|
||||||
relativenumber = false,
|
relativenumber = false,
|
||||||
number = false,
|
number = false,
|
||||||
@@ -98,7 +97,6 @@ end
|
|||||||
|
|
||||||
-- set user options and create tree buffer (should never be wiped)
|
-- set user options and create tree buffer (should never be wiped)
|
||||||
function M.setup()
|
function M.setup()
|
||||||
M.View.auto_resize = vim.g.nvim_tree_auto_resize or M.View.auto_resize
|
|
||||||
M.View.side = vim.g.nvim_tree_side or M.View.side
|
M.View.side = vim.g.nvim_tree_side or M.View.side
|
||||||
M.View.width = vim.g.nvim_tree_width or M.View.width
|
M.View.width = vim.g.nvim_tree_width or M.View.width
|
||||||
|
|
||||||
@@ -123,6 +121,30 @@ function M.setup()
|
|||||||
a.nvim_buf_set_keymap(M.View.bufnr, 'n', key, cb, { noremap = true, silent = true })
|
a.nvim_buf_set_keymap(M.View.bufnr, 'n', key, cb, { noremap = true, silent = true })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
vim.cmd "au! BufWinEnter * lua require'nvim-tree.view'._prevent_buffer_override()"
|
||||||
|
end
|
||||||
|
|
||||||
|
local goto_tbl = {
|
||||||
|
right = 'h',
|
||||||
|
left = 'l',
|
||||||
|
top = 'j',
|
||||||
|
bottom = 'k',
|
||||||
|
}
|
||||||
|
|
||||||
|
function M._prevent_buffer_override()
|
||||||
|
local curwin = a.nvim_get_current_win()
|
||||||
|
local curbuf = a.nvim_win_get_buf(curwin)
|
||||||
|
if curwin ~= M.View.winnr or curbuf == M.View.bufnr then return end
|
||||||
|
|
||||||
|
vim.cmd("buffer "..M.View.bufnr)
|
||||||
|
|
||||||
|
if #vim.api.nvim_list_wins() < 2 then
|
||||||
|
vim.cmd("vsplit")
|
||||||
|
else
|
||||||
|
vim.cmd("wincmd "..goto_tbl[M.View.side])
|
||||||
|
end
|
||||||
|
vim.cmd("buffer "..curbuf)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.win_open()
|
function M.win_open()
|
||||||
@@ -150,7 +172,7 @@ function M.focus(winnr, open_if_closed)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function M.resize()
|
function M.resize()
|
||||||
if not M.View.auto_resize then
|
if not a.nvim_win_is_valid(M.View.winnr) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user