Merge branch 'master' into 2941-move-lib-to-explorer
This commit is contained in:
@@ -2,6 +2,8 @@ local log = require("nvim-tree.log")
|
||||
local view = require("nvim-tree.view")
|
||||
local utils = require("nvim-tree.utils")
|
||||
local core = require("nvim-tree.core")
|
||||
|
||||
local DirectoryNode = require("nvim-tree.node.directory")
|
||||
local Iterator = require("nvim-tree.iterators.node-iterator")
|
||||
|
||||
local M = {}
|
||||
@@ -59,19 +61,27 @@ function M.fn(path)
|
||||
local link_match = node.link_to and vim.startswith(path_real, node.link_to .. utils.path_separator)
|
||||
|
||||
if abs_match or link_match then
|
||||
if not node.group_next then
|
||||
node.open = true
|
||||
end
|
||||
if #node.nodes == 0 then
|
||||
core.get_explorer():expand(node)
|
||||
if node.group_next and incremented_line then
|
||||
line = line - 1
|
||||
local dir = node:as(DirectoryNode)
|
||||
if dir then
|
||||
if not dir.group_next then
|
||||
dir.open = true
|
||||
end
|
||||
if #dir.nodes == 0 then
|
||||
core.get_explorer():expand(dir)
|
||||
if dir.group_next and incremented_line then
|
||||
line = line - 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
:recursor(function(node)
|
||||
return node.group_next and { node.group_next } or (node.open and #node.nodes > 0 and node.nodes)
|
||||
node = node and node:as(DirectoryNode)
|
||||
if node then
|
||||
return node.group_next and { node.group_next } or (node.open and #node.nodes > 0 and node.nodes)
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end)
|
||||
:iterate()
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ local function move(explorer, where, what, skip_gitignored)
|
||||
end
|
||||
end
|
||||
|
||||
---@param node Node
|
||||
---@param node DirectoryNode
|
||||
local function expand_node(node)
|
||||
if node:is(DirectoryNode) and not node.open then
|
||||
---@cast node DirectoryNode
|
||||
@@ -101,9 +101,9 @@ local function move_next_recursive(explorer, what, skip_gitignored)
|
||||
if node_init.name ~= ".." then -- root node cannot have a status
|
||||
valid = status_is_valid(node_init, what, skip_gitignored)
|
||||
end
|
||||
if node_init:is(DirectoryNode) and valid and not node_init.open then
|
||||
---@cast node_init DirectoryNode
|
||||
node_init:expand_or_collapse(false)
|
||||
local node_dir = node_init:as(DirectoryNode)
|
||||
if node_dir and valid and not node_dir.open then
|
||||
node_dir:expand_or_collapse(false)
|
||||
end
|
||||
|
||||
move(explorer, "next", what, skip_gitignored)
|
||||
@@ -120,20 +120,15 @@ local function move_next_recursive(explorer, what, skip_gitignored)
|
||||
|
||||
-- i is used to limit iterations.
|
||||
local i = 0
|
||||
local is_dir = node_cur.nodes ~= nil
|
||||
while is_dir and i < MAX_DEPTH do
|
||||
expand_node(node_cur)
|
||||
local dir_cur = node_cur:as(DirectoryNode)
|
||||
while dir_cur and i < MAX_DEPTH do
|
||||
expand_node(dir_cur)
|
||||
|
||||
move(explorer, "next", what, skip_gitignored)
|
||||
|
||||
-- Save current node.
|
||||
node_cur = explorer:get_node_at_cursor()
|
||||
-- Update is_dir.
|
||||
if node_cur then
|
||||
is_dir = node_cur.nodes ~= nil
|
||||
else
|
||||
is_dir = false
|
||||
end
|
||||
dir_cur = node_cur and node_cur:as(DirectoryNode)
|
||||
|
||||
i = i + 1
|
||||
end
|
||||
@@ -187,8 +182,10 @@ local function move_prev_recursive(explorer, what, skip_gitignored)
|
||||
end
|
||||
|
||||
-- 4.2)
|
||||
local node_dir = node_cur
|
||||
expand_node(node_dir)
|
||||
local node_dir = node_cur:as(DirectoryNode)
|
||||
if node_dir then
|
||||
expand_node(node_dir)
|
||||
end
|
||||
|
||||
-- 4.3)
|
||||
if node_init.name == ".." then -- root node
|
||||
|
||||
@@ -331,9 +331,9 @@ local function open_in_new_window(filename, mode)
|
||||
|
||||
local fname
|
||||
if M.relative_path then
|
||||
fname = vim.fn.fnameescape(utils.path_relative(filename, vim.fn.getcwd()))
|
||||
fname = utils.escape_special_chars(vim.fn.fnameescape(utils.path_relative(filename, vim.fn.getcwd())))
|
||||
else
|
||||
fname = vim.fn.fnameescape(filename)
|
||||
fname = utils.escape_special_chars(vim.fn.fnameescape(filename))
|
||||
end
|
||||
|
||||
local command
|
||||
@@ -370,28 +370,27 @@ end
|
||||
---@param mode string
|
||||
---@param filename string
|
||||
function M.fn(mode, filename)
|
||||
local fname = utils.escape_special_chars(filename)
|
||||
if type(mode) ~= "string" then
|
||||
mode = ""
|
||||
end
|
||||
|
||||
if mode == "tabnew" then
|
||||
return open_file_in_tab(fname)
|
||||
return open_file_in_tab(filename)
|
||||
end
|
||||
|
||||
if mode == "drop" then
|
||||
return drop(fname)
|
||||
return drop(filename)
|
||||
end
|
||||
|
||||
if mode == "tab_drop" then
|
||||
return tab_drop(fname)
|
||||
return tab_drop(filename)
|
||||
end
|
||||
|
||||
if mode == "edit_in_place" then
|
||||
return edit_in_current_buf(fname)
|
||||
return edit_in_current_buf(filename)
|
||||
end
|
||||
|
||||
local buf_loaded = is_already_loaded(fname)
|
||||
local buf_loaded = is_already_loaded(filename)
|
||||
|
||||
local found_win = utils.get_win_buf_from_path(filename)
|
||||
if found_win and (mode == "preview" or mode == "preview_no_picker") then
|
||||
@@ -399,7 +398,7 @@ function M.fn(mode, filename)
|
||||
end
|
||||
|
||||
if not found_win then
|
||||
open_in_new_window(fname, mode)
|
||||
open_in_new_window(filename, mode)
|
||||
else
|
||||
vim.api.nvim_set_current_win(found_win)
|
||||
vim.bo.bufhidden = ""
|
||||
|
||||
Reference in New Issue
Block a user