summaryrefslogtreecommitdiff
path: root/lua/core/nvimtree.lua
diff options
context:
space:
mode:
authorAhmed Khalf <[email protected]>2021-08-20 11:31:18 +0400
committerGitHub <[email protected]>2021-08-20 09:31:18 +0200
commit59598723077ac6728fc585c3c88e0ec84ba430c3 (patch)
treeca663c545cb962234f3fbed862df8c95e1b8069e /lua/core/nvimtree.lua
parent1f45d1531d3636102f8971f8b2103b5302f48b68 (diff)
[Refactor]: consistent update of bufferline offset with nvim-tree (#1351)
* Refactor nvim-tree * Fix stylua comments * Delete useless functions * Remove autocmd and fix tasty's bug * Fix luacheck * Fix icon issue * Fix formatting * Fix formatting again * Resolve Tasty's request * Replace double dashes with blank line
Diffstat (limited to 'lua/core/nvimtree.lua')
-rw-r--r--lua/core/nvimtree.lua78
1 files changed, 28 insertions, 50 deletions
diff --git a/lua/core/nvimtree.lua b/lua/core/nvimtree.lua
index 737f248e..ff52029d 100644
--- a/lua/core/nvimtree.lua
+++ b/lua/core/nvimtree.lua
@@ -1,6 +1,6 @@
local M = {}
local Log = require "core.log"
---
+
M.config = function()
lvim.builtin.nvimtree = {
active = true,
@@ -47,7 +47,7 @@ M.config = function()
},
}
end
---
+
M.setup = function()
local status_ok, nvim_tree_config = pcall(require, "nvim-tree.config")
if not status_ok then
@@ -73,64 +73,42 @@ M.setup = function()
{ key = { "l", "<CR>", "o" }, cb = tree_cb "edit" },
{ key = "h", cb = tree_cb "close_node" },
{ key = "v", cb = tree_cb "vsplit" },
- { key = "q", cb = ":lua require('core.nvimtree').toggle_tree()<cr>" },
}
end
-end
---
-M.focus_or_close = function()
- local view_status_ok, view = pcall(require, "nvim-tree.view")
- if not view_status_ok then
- return
- end
- local a = vim.api
- local curwin = a.nvim_get_current_win()
- local curbuf = a.nvim_win_get_buf(curwin)
- local bufnr = view.View.bufnr
- local winnr = view.get_winnr()
+ lvim.builtin.which_key.mappings["e"] = { "<cmd>NvimTreeToggle<CR>", "Explorer" }
+
+ local tree_view = require "nvim-tree.view"
- if view.win_open() then
- if curwin == winnr and curbuf == bufnr then
- view.close()
- if package.loaded["bufferline.state"] then
- require("bufferline.state").set_offset(0)
- end
- else
- view.focus()
- end
- else
- view.open()
- if package.loaded["bufferline.state"] and lvim.builtin.nvimtree.side == "left" then
- -- require'bufferline.state'.set_offset(lvim.builtin.nvimtree.width + 1, 'File Explorer')
- require("bufferline.state").set_offset(lvim.builtin.nvimtree.width + 1, "")
- end
+ -- Add nvim_tree open callback
+ local open = tree_view.open
+ tree_view.open = function()
+ M.on_open()
+ open()
end
+
+ vim.cmd "au WinClosed * lua require('core.nvimtree').on_close()"
end
---
-M.toggle_tree = function()
- local view_status_ok, view = pcall(require, "nvim-tree.view")
- if not view_status_ok then
- return
+
+M.on_open = function()
+ if package.loaded["bufferline.state"] and lvim.builtin.nvimtree.side == "left" then
+ require("bufferline.state").set_offset(lvim.builtin.nvimtree.width + 1, "")
end
- if view.win_open() then
- require("nvim-tree").close()
- if package.loaded["bufferline.state"] then
- require("bufferline.state").set_offset(0)
- end
- else
- if package.loaded["bufferline.state"] and lvim.builtin.nvimtree.side == "left" then
- -- require'bufferline.state'.set_offset(lvim.builtin.nvimtree.width + 1, 'File Explorer')
- require("bufferline.state").set_offset(lvim.builtin.nvimtree.width + 1, "")
- end
- require("nvim-tree").toggle()
+end
+
+M.on_close = function()
+ local buf = tonumber(vim.fn.expand "<abuf>")
+ local ft = vim.api.nvim_buf_get_option(buf, "filetype")
+ if ft == "NvimTree" and package.loaded["bufferline.state"] then
+ require("bufferline.state").set_offset(0)
end
end
---
+
function M.change_tree_dir(dir)
- if vim.g.loaded_tree then
- require("nvim-tree.lib").change_dir(dir)
+ local lib_status_ok, lib = pcall(require, "nvim-tree.lib")
+ if lib_status_ok then
+ lib.change_dir(dir)
end
end
---
+
return M