* refactor(#2826): singleton View class, WIP * refactor(#2826): singleton View class, WIP * refactor(#2826): singleton View class, WIP * refactor(#2826): singleton View class, WIP * refactor(#2826): singleton View class, WIP * refactor(#2826): singleton View class, WIP * refactor(#2826): singleton View class, WIP * refactor(#2826): singleton View class * refactor(#2826): View is an Explorer member * refactor(#2826): move autocmds to Explorer * refactor(#2826): API uses Explorer's View * refactor(#2826): move View into Explorer package * refactor(#2826): retain necessary view globals * refactor(#2826): move all winhl to appearance constants * refactor(#2826): add lifecycle logging to all Explorer members * refactor(#2826): fix bad cherry-pick * refactor(#2826): better enumerate_options function * refactor(#2826): add View.tab_line for debugging * refactor(#2826): default lifecycle log off * refactor(#2826): add experimental.multi_instance_debug, split globals out of view, move diagnostics to its own module * refactor(#2826): instrument View:get_winnr * refactor(#2826): instrument View:setup_tabpage * refactor(#2826): instrument View:set_current_win, View:prevent_buffer_override * refactor(#2826): instrument View:get_bufnr * refactor(#2826): track member bufnr -> winid with global * refactor(#2826): tidy experiment names and logs * vim: nvim-tree: track bufnr via buffer-update channel * vim: nvim-tree: more logging * vim: nvim-tree: revert: track bufnr via buffer-update channel * refactor(#2826): notify error on view winid and bufnr mismatches * refactor(#2826): notify error on view winid and bufnr mismatches * refactor(#2826): explorer init logging
This commit is contained in:
committed by
GitHub
parent
d54a1875a9
commit
0a06f65bf0
@@ -1,4 +1,3 @@
|
||||
local view = require("nvim-tree.view")
|
||||
local core = require("nvim-tree.core")
|
||||
local notify = require("nvim-tree.notify")
|
||||
|
||||
@@ -12,9 +11,11 @@ local M = {
|
||||
}
|
||||
|
||||
function M.set_target_win()
|
||||
local explorer = core.get_explorer()
|
||||
|
||||
local id = vim.api.nvim_get_current_win()
|
||||
local tree_id = view.get_winnr()
|
||||
if tree_id and id == tree_id then
|
||||
|
||||
if explorer and id == explorer.view:get_winnr(nil, "lib.set_target_win") then
|
||||
M.target_winid = 0
|
||||
return
|
||||
end
|
||||
@@ -30,11 +31,16 @@ local function handle_buf_cwd(cwd)
|
||||
end
|
||||
|
||||
local function open_view_and_draw()
|
||||
local explorer = core.get_explorer()
|
||||
|
||||
local cwd = vim.fn.getcwd()
|
||||
view.open()
|
||||
|
||||
if explorer then
|
||||
explorer.view:open()
|
||||
end
|
||||
|
||||
handle_buf_cwd(cwd)
|
||||
|
||||
local explorer = core.get_explorer()
|
||||
if explorer then
|
||||
explorer.renderer:draw()
|
||||
end
|
||||
@@ -96,39 +102,42 @@ function M.open(opts)
|
||||
M.set_target_win()
|
||||
if not core.get_explorer() or opts.path then
|
||||
if opts.path then
|
||||
core.init(opts.path)
|
||||
core.init(opts.path, "lib.open - opts.path")
|
||||
else
|
||||
local cwd, err = vim.loop.cwd()
|
||||
if not cwd then
|
||||
notify.error(string.format("current working directory unavailable: %s", err))
|
||||
return
|
||||
end
|
||||
core.init(cwd)
|
||||
core.init(cwd, "lib.open - cwd")
|
||||
end
|
||||
end
|
||||
|
||||
local explorer = core.get_explorer()
|
||||
|
||||
if should_hijack_current_buf() then
|
||||
view.close_this_tab_only()
|
||||
view.open_in_win()
|
||||
if explorer then
|
||||
explorer.view:close_this_tab_only()
|
||||
explorer.view:open_in_win()
|
||||
explorer.renderer:draw()
|
||||
end
|
||||
elseif opts.winid then
|
||||
view.open_in_win({ hijack_current_buf = false, resize = false, winid = opts.winid })
|
||||
if explorer then
|
||||
explorer.view:open_in_win({ hijack_current_buf = false, resize = false, winid = opts.winid })
|
||||
explorer.renderer:draw()
|
||||
end
|
||||
elseif opts.current_window then
|
||||
view.open_in_win({ hijack_current_buf = false, resize = false })
|
||||
if explorer then
|
||||
explorer.view:open_in_win({ hijack_current_buf = false, resize = false })
|
||||
explorer.renderer:draw()
|
||||
end
|
||||
else
|
||||
open_view_and_draw()
|
||||
end
|
||||
view.restore_tab_state()
|
||||
|
||||
if explorer then
|
||||
explorer.view:restore_tab_state()
|
||||
end
|
||||
end
|
||||
|
||||
function M.setup(opts)
|
||||
|
||||
Reference in New Issue
Block a user