refactor(#2826): split global View and instance Window
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
local log = require("nvim-tree.log")
|
||||
local view = require("nvim-tree.view")
|
||||
local utils = require("nvim-tree.utils")
|
||||
local core = require("nvim-tree.core")
|
||||
|
||||
@@ -13,7 +14,7 @@ local running = {}
|
||||
---@param path string relative or absolute
|
||||
function M.fn(path)
|
||||
local explorer = core.get_explorer()
|
||||
if not explorer or not explorer.window:is_visible() then
|
||||
if not explorer or not view.is_visible() then
|
||||
return
|
||||
end
|
||||
|
||||
@@ -83,9 +84,9 @@ function M.fn(path)
|
||||
end)
|
||||
:iterate()
|
||||
|
||||
if found and explorer.window:is_visible() then
|
||||
if found and view.is_visible() then
|
||||
explorer.renderer:draw()
|
||||
explorer.window:set_cursor({ line, 0 })
|
||||
view.set_cursor({ line, 0 })
|
||||
end
|
||||
|
||||
running[path_real] = false
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
local utils = require("nvim-tree.utils")
|
||||
local view = require("nvim-tree.view")
|
||||
local core = require("nvim-tree.core")
|
||||
local diagnostics = require("nvim-tree.diagnostics")
|
||||
|
||||
@@ -66,9 +67,9 @@ local function move(explorer, where, what, skip_gitignored)
|
||||
end
|
||||
|
||||
if nex then
|
||||
explorer.window:set_cursor({ nex, 0 })
|
||||
view.set_cursor({ nex, 0 })
|
||||
elseif vim.o.wrapscan and first then
|
||||
explorer.window:set_cursor({ first, 0 })
|
||||
view.set_cursor({ first, 0 })
|
||||
end
|
||||
end
|
||||
|
||||
@@ -188,13 +189,13 @@ local function move_prev_recursive(explorer, what, skip_gitignored)
|
||||
|
||||
-- 4.3)
|
||||
if node_init.name == ".." then -- root node
|
||||
explorer.window:set_cursor({ 1, 0 }) -- move to root node (position 1)
|
||||
view.set_cursor({ 1, 0 }) -- move to root node (position 1)
|
||||
else
|
||||
local node_init_line = utils.find_node_line(node_init)
|
||||
if node_init_line < 0 then
|
||||
return
|
||||
end
|
||||
explorer.window:set_cursor({ node_init_line, 0 })
|
||||
view.set_cursor({ node_init_line, 0 })
|
||||
end
|
||||
|
||||
-- 4.4)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
local view = require("nvim-tree.view")
|
||||
local utils = require("nvim-tree.utils")
|
||||
|
||||
local DirectoryNode = require("nvim-tree.node.directory")
|
||||
@@ -24,7 +25,7 @@ function M.fn(should_close)
|
||||
local parent = (node:get_parent_of_group() or node).parent
|
||||
|
||||
if not parent or not parent.parent then
|
||||
node.explorer.window:set_cursor({ 1, 0 })
|
||||
view.set_cursor({ 1, 0 })
|
||||
return
|
||||
end
|
||||
|
||||
@@ -32,7 +33,7 @@ function M.fn(should_close)
|
||||
return n.absolute_path == parent.absolute_path
|
||||
end)
|
||||
|
||||
node.explorer.window:set_cursor({ line + 1, 0 })
|
||||
view.set_cursor({ line + 1, 0 })
|
||||
if should_close then
|
||||
parent.open = false
|
||||
parent.explorer.renderer:draw()
|
||||
|
||||
@@ -3,6 +3,7 @@ local lib = require("nvim-tree.lib")
|
||||
local notify = require("nvim-tree.notify")
|
||||
local utils = require("nvim-tree.utils")
|
||||
local core = require("nvim-tree.core")
|
||||
local view = require("nvim-tree.view")
|
||||
|
||||
local M = {}
|
||||
|
||||
@@ -19,10 +20,9 @@ end
|
||||
---Get all windows in the current tabpage that aren't NvimTree.
|
||||
---@return table with valid win_ids
|
||||
local function usable_win_ids()
|
||||
local explorer = core.get_explorer()
|
||||
local tabpage = vim.api.nvim_get_current_tabpage()
|
||||
local win_ids = vim.api.nvim_tabpage_list_wins(tabpage)
|
||||
local tree_winid = explorer and explorer.window:get_winnr(tabpage)
|
||||
local tree_winid = view.get_winnr(tabpage)
|
||||
|
||||
return vim.tbl_filter(function(id)
|
||||
local bufid = vim.api.nvim_win_get_buf(id)
|
||||
@@ -386,12 +386,7 @@ local function is_already_loaded(filename)
|
||||
end
|
||||
|
||||
local function edit_in_current_buf(filename)
|
||||
local explorer = core.get_explorer()
|
||||
|
||||
if explorer then
|
||||
explorer.window:abandon_current_window()
|
||||
end
|
||||
|
||||
require("nvim-tree.view").abandon_current_window()
|
||||
if M.relative_path then
|
||||
filename = utils.path_relative(filename, vim.fn.getcwd())
|
||||
end
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
local core = require("nvim-tree.core")
|
||||
local lib = require("nvim-tree.lib")
|
||||
local view = require("nvim-tree.view")
|
||||
local finders_find_file = require("nvim-tree.actions.finders.find-file")
|
||||
|
||||
local M = {}
|
||||
@@ -41,7 +42,7 @@ function M.fn(opts)
|
||||
end
|
||||
|
||||
local explorer = core.get_explorer()
|
||||
if explorer and explorer.window:is_visible() then
|
||||
if explorer and view.is_visible() then
|
||||
-- focus
|
||||
if opts.focus then
|
||||
lib.set_target_win()
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
local core = require("nvim-tree.core")
|
||||
local lib = require("nvim-tree.lib")
|
||||
local view = require("nvim-tree.view")
|
||||
local finders_find_file = require("nvim-tree.actions.finders.find-file")
|
||||
|
||||
local M = {}
|
||||
@@ -25,7 +26,7 @@ function M.fn(opts)
|
||||
|
||||
local explorer = core.get_explorer()
|
||||
|
||||
if explorer and explorer.window:is_visible() then
|
||||
if explorer and view.is_visible() then
|
||||
-- focus
|
||||
lib.set_target_win()
|
||||
explorer.window:focus()
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
local core = require("nvim-tree.core")
|
||||
local lib = require("nvim-tree.lib")
|
||||
local view = require("nvim-tree.view")
|
||||
local finders_find_file = require("nvim-tree.actions.finders.find-file")
|
||||
|
||||
local M = {}
|
||||
@@ -42,7 +43,7 @@ function M.fn(opts, no_focus, cwd, bang)
|
||||
opts.path = nil
|
||||
end
|
||||
|
||||
if explorer and explorer.window:is_visible() then
|
||||
if explorer and view.is_visible() then
|
||||
-- close
|
||||
explorer.window:close()
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user