Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7c0f7e906a | |||
|
|
64e2192f52 | ||
|
|
e397756d2a | ||
|
|
87d096a39c | ||
|
|
01b2e8e5f7 | ||
|
|
e179ad2f83 | ||
|
|
f92cc3a91c | ||
|
|
fefa335f1c | ||
|
|
b70a741f5a | ||
|
|
f4fa6ebd3c | ||
|
|
f0e9951778 | ||
|
|
feb901a09e |
8
.github/workflows/ci.yml
vendored
8
.github/workflows/ci.yml
vendored
@ -24,15 +24,15 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: checkout
|
- name: checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v5
|
||||||
|
|
||||||
- name: install lua ${{ matrix.lua_version }}
|
- name: install lua ${{ matrix.lua_version }}
|
||||||
uses: leafo/gh-actions-lua@v11
|
uses: leafo/gh-actions-lua@v12
|
||||||
with:
|
with:
|
||||||
luaVersion: ${{ matrix.lua_version }}
|
luaVersion: ${{ matrix.lua_version }}
|
||||||
|
|
||||||
- name: install luarocks
|
- name: install luarocks
|
||||||
uses: leafo/gh-actions-luarocks@v5
|
uses: leafo/gh-actions-luarocks@v6
|
||||||
|
|
||||||
- name: install luacheck ${{ matrix.luacheck_version }}
|
- name: install luacheck ${{ matrix.luacheck_version }}
|
||||||
run: luarocks install luacheck ${{ matrix.luacheck_version }}
|
run: luarocks install luacheck ${{ matrix.luacheck_version }}
|
||||||
@ -56,7 +56,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: checkout
|
- name: checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v5
|
||||||
|
|
||||||
- name: install nvim ${{ matrix.nvim_version }}
|
- name: install nvim ${{ matrix.nvim_version }}
|
||||||
uses: rhysd/action-setup-vim@v1
|
uses: rhysd/action-setup-vim@v1
|
||||||
|
|||||||
2
.github/workflows/luarocks-release.yml
vendored
2
.github/workflows/luarocks-release.yml
vendored
@ -10,7 +10,7 @@ jobs:
|
|||||||
luarocks-upload:
|
luarocks-upload:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
- name: LuaRocks Upload
|
- name: LuaRocks Upload
|
||||||
uses: nvim-neorocks/luarocks-tag-release@v7
|
uses: nvim-neorocks/luarocks-tag-release@v7
|
||||||
env:
|
env:
|
||||||
|
|||||||
2
.github/workflows/release-please.yml
vendored
2
.github/workflows/release-please.yml
vendored
@ -16,7 +16,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: google-github-actions/release-please-action@v4
|
- uses: google-github-actions/release-please-action@v4
|
||||||
id: release
|
id: release
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
- name: tag major and minor versions
|
- name: tag major and minor versions
|
||||||
if: ${{ steps.release.outputs.release_created }}
|
if: ${{ steps.release.outputs.release_created }}
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
2
.github/workflows/semantic-pr-subject.yml
vendored
2
.github/workflows/semantic-pr-subject.yml
vendored
@ -14,6 +14,6 @@ jobs:
|
|||||||
semantic-pr-subject:
|
semantic-pr-subject:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: amannn/action-semantic-pull-request@v5.5.3
|
- uses: amannn/action-semantic-pull-request@v6.1.1
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|||||||
@ -545,6 +545,7 @@ Following is the default configuration. See |nvim-tree-opts| for details. >lua
|
|||||||
warning = "",
|
warning = "",
|
||||||
error = "",
|
error = "",
|
||||||
},
|
},
|
||||||
|
diagnostic_opts = false,
|
||||||
},
|
},
|
||||||
modified = {
|
modified = {
|
||||||
enable = false,
|
enable = false,
|
||||||
@ -1329,6 +1330,10 @@ Icons for diagnostic severity.
|
|||||||
error = ""
|
error = ""
|
||||||
}
|
}
|
||||||
<
|
<
|
||||||
|
*nvim-tree.diagnostics.diagnostic_opts*
|
||||||
|
|vim.diagnostic.Opts| overrides |nvim-tree.diagnostics.severity| and
|
||||||
|
|nvim-tree.diagnostics.icons|
|
||||||
|
Type: `boolean`, Default: `false`
|
||||||
==============================================================================
|
==============================================================================
|
||||||
5.9 OPTS: MODIFIED *nvim-tree-opts-modified*
|
5.9 OPTS: MODIFIED *nvim-tree-opts-modified*
|
||||||
|
|
||||||
@ -2334,6 +2339,7 @@ events.Event *nvim-tree-api.events.Event*
|
|||||||
|
|
||||||
live_filter.start() *nvim-tree-api.live_filter.start()*
|
live_filter.start() *nvim-tree-api.live_filter.start()*
|
||||||
Enter |nvim-tree.live_filter| mode.
|
Enter |nvim-tree.live_filter| mode.
|
||||||
|
Opens an input window with |filetype| `"NvimTreeFilter"`
|
||||||
|
|
||||||
live_filter.clear() *nvim-tree-api.live_filter.clear()*
|
live_filter.clear() *nvim-tree-api.live_filter.clear()*
|
||||||
Exit |nvim-tree.live_filter| mode.
|
Exit |nvim-tree.live_filter| mode.
|
||||||
@ -3175,6 +3181,7 @@ highlight group is not, hard linking as follows: >
|
|||||||
|nvim-tree.actions.use_system_clipboard|
|
|nvim-tree.actions.use_system_clipboard|
|
||||||
|nvim-tree.auto_reload_on_write|
|
|nvim-tree.auto_reload_on_write|
|
||||||
|nvim-tree.diagnostics.debounce_delay|
|
|nvim-tree.diagnostics.debounce_delay|
|
||||||
|
|nvim-tree.diagnostics.diagnostic_opts|
|
||||||
|nvim-tree.diagnostics.enable|
|
|nvim-tree.diagnostics.enable|
|
||||||
|nvim-tree.diagnostics.icons|
|
|nvim-tree.diagnostics.icons|
|
||||||
|nvim-tree.diagnostics.severity|
|
|nvim-tree.diagnostics.severity|
|
||||||
|
|||||||
@ -420,6 +420,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
|
|||||||
warning = "",
|
warning = "",
|
||||||
error = "",
|
error = "",
|
||||||
},
|
},
|
||||||
|
diagnostic_opts = false,
|
||||||
},
|
},
|
||||||
modified = {
|
modified = {
|
||||||
enable = false,
|
enable = false,
|
||||||
|
|||||||
@ -32,7 +32,7 @@ function M.fn(path)
|
|||||||
local profile = log.profile_start("find file %s", path_real)
|
local profile = log.profile_start("find file %s", path_real)
|
||||||
|
|
||||||
-- refresh the contents of all parents, expanding groups as needed
|
-- refresh the contents of all parents, expanding groups as needed
|
||||||
if utils.get_node_from_path(path_real) == nil then
|
if explorer:get_node_from_path(path_real) == nil then
|
||||||
explorer:refresh_parent_nodes_for_path(vim.fn.fnamemodify(path_real, ":h"))
|
explorer:refresh_parent_nodes_for_path(vim.fn.fnamemodify(path_real, ":h"))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
local utils = require("nvim-tree.utils")
|
|
||||||
local view = require("nvim-tree.view")
|
local view = require("nvim-tree.view")
|
||||||
local core = require("nvim-tree.core")
|
local core = require("nvim-tree.core")
|
||||||
local diagnostics = require("nvim-tree.diagnostics")
|
local diagnostics = require("nvim-tree.diagnostics")
|
||||||
@ -36,7 +35,7 @@ end
|
|||||||
---@param skip_gitignored boolean? default false
|
---@param skip_gitignored boolean? default false
|
||||||
local function move(explorer, where, what, skip_gitignored)
|
local function move(explorer, where, what, skip_gitignored)
|
||||||
local first_node_line = core.get_nodes_starting_line()
|
local first_node_line = core.get_nodes_starting_line()
|
||||||
local nodes_by_line = utils.get_nodes_by_line(explorer.nodes, first_node_line)
|
local nodes_by_line = explorer:get_nodes_by_line(first_node_line)
|
||||||
local iter_start, iter_end, iter_step, cur, first, nex
|
local iter_start, iter_end, iter_step, cur, first, nex
|
||||||
|
|
||||||
local cursor = explorer:get_cursor_position()
|
local cursor = explorer:get_cursor_position()
|
||||||
@ -191,7 +190,7 @@ local function move_prev_recursive(explorer, what, skip_gitignored)
|
|||||||
if node_init.name == ".." then -- root node
|
if node_init.name == ".." then -- root node
|
||||||
view.set_cursor({ 1, 0 }) -- move to root node (position 1)
|
view.set_cursor({ 1, 0 }) -- move to root node (position 1)
|
||||||
else
|
else
|
||||||
local node_init_line = utils.find_node_line(node_init)
|
local node_init_line = explorer:find_node_line(node_init)
|
||||||
if node_init_line < 0 then
|
if node_init_line < 0 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,6 +1,4 @@
|
|||||||
local view = require("nvim-tree.view")
|
local view = require("nvim-tree.view")
|
||||||
local utils = require("nvim-tree.utils")
|
|
||||||
|
|
||||||
local DirectoryNode = require("nvim-tree.node.directory")
|
local DirectoryNode = require("nvim-tree.node.directory")
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
@ -29,7 +27,7 @@ function M.fn(should_close)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local _, line = utils.find_node(parent.explorer.nodes, function(n)
|
local _, line = parent.explorer:find_node(function(n)
|
||||||
return n.absolute_path == parent.absolute_path
|
return n.absolute_path == parent.absolute_path
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
local utils = require("nvim-tree.utils")
|
|
||||||
local core = require("nvim-tree.core")
|
local core = require("nvim-tree.core")
|
||||||
local Iterator = require("nvim-tree.iterators.node-iterator")
|
local Iterator = require("nvim-tree.iterators.node-iterator")
|
||||||
|
|
||||||
@ -12,9 +11,14 @@ function M.fn(direction)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local explorer = core.get_explorer()
|
||||||
|
if not explorer then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local first, last, next, prev = nil, nil, nil, nil
|
local first, last, next, prev = nil, nil, nil, nil
|
||||||
local found = false
|
local found = false
|
||||||
local parent = node.parent or core.get_explorer()
|
local parent = node.parent or explorer
|
||||||
Iterator.builder(parent and parent.nodes or {})
|
Iterator.builder(parent and parent.nodes or {})
|
||||||
:recursor(function()
|
:recursor(function()
|
||||||
return nil
|
return nil
|
||||||
@ -45,7 +49,7 @@ function M.fn(direction)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if target_node then
|
if target_node then
|
||||||
utils.focus_file(target_node.absolute_path)
|
explorer:focus_node_or_parent(target_node)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -198,7 +198,15 @@ local function open_file_in_tab(filename)
|
|||||||
if M.relative_path then
|
if M.relative_path then
|
||||||
filename = utils.path_relative(filename, vim.fn.getcwd())
|
filename = utils.path_relative(filename, vim.fn.getcwd())
|
||||||
end
|
end
|
||||||
vim.cmd("tabe " .. vim.fn.fnameescape(filename))
|
vim.cmd.tabnew()
|
||||||
|
vim.bo.bufhidden = "wipe"
|
||||||
|
-- Following vim.fn.tabnew the # buffer may be set to the tree buffer. There is no way to clear the # buffer via vim.fn.setreg as it requires a valid buffer. Clear # by setting it to a new temporary scratch buffer.
|
||||||
|
if utils.is_nvim_tree_buf(vim.fn.bufnr("#")) then
|
||||||
|
local tmpbuf = vim.api.nvim_create_buf(false, true)
|
||||||
|
vim.fn.setreg("#", tmpbuf)
|
||||||
|
vim.api.nvim_buf_delete(tmpbuf, { force = true })
|
||||||
|
end
|
||||||
|
vim.cmd.edit(vim.fn.fnameescape(filename))
|
||||||
end
|
end
|
||||||
|
|
||||||
local function drop(filename)
|
local function drop(filename)
|
||||||
|
|||||||
@ -56,7 +56,7 @@ local function collapse(node, opts)
|
|||||||
:iterate()
|
:iterate()
|
||||||
|
|
||||||
explorer.renderer:draw()
|
explorer.renderer:draw()
|
||||||
utils.focus_node_or_parent(node_at_cursor)
|
explorer:focus_node_or_parent(node_at_cursor)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -231,7 +231,10 @@ end
|
|||||||
function M.setup(opts)
|
function M.setup(opts)
|
||||||
M.enable = opts.diagnostics.enable
|
M.enable = opts.diagnostics.enable
|
||||||
M.debounce_delay = opts.diagnostics.debounce_delay
|
M.debounce_delay = opts.diagnostics.debounce_delay
|
||||||
M.severity = opts.diagnostics.severity
|
M.severity = opts.diagnostics.diagnostic_opts and {
|
||||||
|
min = vim.diagnostic.severity.HINT,
|
||||||
|
max = vim.diagnostic.severity.ERROR
|
||||||
|
} or opts.diagnostics.severity
|
||||||
|
|
||||||
if M.enable then
|
if M.enable then
|
||||||
log.line("diagnostics", "setup")
|
log.line("diagnostics", "setup")
|
||||||
|
|||||||
@ -280,7 +280,7 @@ function Filters:toggle(type)
|
|||||||
local node = self.explorer:get_node_at_cursor()
|
local node = self.explorer:get_node_at_cursor()
|
||||||
self.explorer:reload_explorer()
|
self.explorer:reload_explorer()
|
||||||
if node then
|
if node then
|
||||||
utils.focus_node_or_parent(node)
|
self.explorer:focus_node_or_parent(node)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -527,7 +527,7 @@ function Explorer:get_node_at_cursor()
|
|||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
return utils.get_nodes_by_line(self.nodes, core.get_nodes_starting_line())[cursor[1]]
|
return self:get_nodes_by_line(core.get_nodes_starting_line())[cursor[1]]
|
||||||
end
|
end
|
||||||
|
|
||||||
function Explorer:place_cursor_on_node()
|
function Explorer:place_cursor_on_node()
|
||||||
@ -551,6 +551,114 @@ function Explorer:place_cursor_on_node()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Find the line number of a node.
|
||||||
|
---@param node Node?
|
||||||
|
---@return integer -1 not found
|
||||||
|
function Explorer:find_node_line(node)
|
||||||
|
if not node then
|
||||||
|
return -1
|
||||||
|
end
|
||||||
|
|
||||||
|
local first_node_line = core.get_nodes_starting_line()
|
||||||
|
local nodes_by_line = self:get_nodes_by_line(first_node_line)
|
||||||
|
local iter_start, iter_end = first_node_line, #nodes_by_line
|
||||||
|
|
||||||
|
for line = iter_start, iter_end, 1 do
|
||||||
|
if nodes_by_line[line] == node then
|
||||||
|
return line
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return -1
|
||||||
|
end
|
||||||
|
|
||||||
|
-- get the node in the tree state depending on the absolute path of the node
|
||||||
|
-- (grouped or hidden too)
|
||||||
|
---@param path string
|
||||||
|
---@return Node|nil
|
||||||
|
---@return number|nil
|
||||||
|
function Explorer:get_node_from_path(path)
|
||||||
|
if self.absolute_path == path then
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
return Iterator.builder(self.nodes)
|
||||||
|
:hidden()
|
||||||
|
:matcher(function(node)
|
||||||
|
return node.absolute_path == path or node.link_to == path
|
||||||
|
end)
|
||||||
|
:recursor(function(node)
|
||||||
|
if node.group_next then
|
||||||
|
return { node.group_next }
|
||||||
|
end
|
||||||
|
if node.nodes then
|
||||||
|
return node.nodes
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
:iterate()
|
||||||
|
end
|
||||||
|
|
||||||
|
---Focus node passed as parameter if visible, otherwise focus first visible parent.
|
||||||
|
---If none of the parents is visible focus root.
|
||||||
|
---If node is nil do nothing.
|
||||||
|
---@param node Node? node to focus
|
||||||
|
function Explorer:focus_node_or_parent(node)
|
||||||
|
while node do
|
||||||
|
local found_node, i = self:find_node(function(node_)
|
||||||
|
return node_.absolute_path == node.absolute_path
|
||||||
|
end)
|
||||||
|
|
||||||
|
if found_node or node.parent == nil then
|
||||||
|
view.set_cursor({ i + 1, 1 })
|
||||||
|
break
|
||||||
|
end
|
||||||
|
|
||||||
|
node = node.parent
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Get the node and index of the node from the tree that matches the predicate.
|
||||||
|
--- The explored nodes are those displayed on the view.
|
||||||
|
---@param fn fun(node: Node): boolean
|
||||||
|
---@return table|nil
|
||||||
|
---@return number
|
||||||
|
function Explorer:find_node(fn)
|
||||||
|
local node, i = Iterator.builder(self.nodes)
|
||||||
|
:matcher(fn)
|
||||||
|
:recursor(function(node)
|
||||||
|
return node.group_next and { node.group_next } or (node.open and #node.nodes > 0 and node.nodes)
|
||||||
|
end)
|
||||||
|
:iterate()
|
||||||
|
i = view.is_root_folder_visible() and i or i - 1
|
||||||
|
if node and node.explorer.live_filter.filter then
|
||||||
|
i = i + 1
|
||||||
|
end
|
||||||
|
return node, i
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Return visible nodes indexed by line
|
||||||
|
---@param line_start number
|
||||||
|
---@return table
|
||||||
|
function Explorer:get_nodes_by_line(line_start)
|
||||||
|
local nodes_by_line = {}
|
||||||
|
local line = line_start
|
||||||
|
|
||||||
|
Iterator.builder(self.nodes)
|
||||||
|
:applier(function(node)
|
||||||
|
if node.group_next then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
nodes_by_line[line] = node
|
||||||
|
line = line + 1
|
||||||
|
end)
|
||||||
|
:recursor(function(node)
|
||||||
|
return node.group_next and { node.group_next } or (node.open and #node.nodes > 0 and node.nodes)
|
||||||
|
end)
|
||||||
|
:iterate()
|
||||||
|
|
||||||
|
return nodes_by_line
|
||||||
|
end
|
||||||
|
|
||||||
---Api.tree.get_nodes
|
---Api.tree.get_nodes
|
||||||
---@return nvim_tree.api.Node
|
---@return nvim_tree.api.Node
|
||||||
function Explorer:get_nodes()
|
function Explorer:get_nodes()
|
||||||
|
|||||||
@ -188,8 +188,10 @@ local function create_overlay(self)
|
|||||||
|
|
||||||
if vim.fn.has("nvim-0.10") == 1 then
|
if vim.fn.has("nvim-0.10") == 1 then
|
||||||
vim.api.nvim_set_option_value("modifiable", true, { buf = overlay_bufnr })
|
vim.api.nvim_set_option_value("modifiable", true, { buf = overlay_bufnr })
|
||||||
|
vim.api.nvim_set_option_value("filetype", "NvimTreeFilter", { buf = overlay_bufnr })
|
||||||
else
|
else
|
||||||
vim.api.nvim_buf_set_option(overlay_bufnr, "modifiable", true) ---@diagnostic disable-line: deprecated
|
vim.api.nvim_buf_set_option(overlay_bufnr, "modifiable", true) ---@diagnostic disable-line: deprecated
|
||||||
|
vim.api.nvim_buf_set_option(overlay_bufnr, "filetype", "NvimTreeFilter") ---@diagnostic disable-line: deprecated
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.api.nvim_buf_set_lines(overlay_bufnr, 0, -1, false, { self.filter })
|
vim.api.nvim_buf_set_lines(overlay_bufnr, 0, -1, false, { self.filter })
|
||||||
@ -220,9 +222,9 @@ function LiveFilter:clear_filter()
|
|||||||
self.explorer.renderer:draw()
|
self.explorer.renderer:draw()
|
||||||
|
|
||||||
if node then
|
if node then
|
||||||
utils.focus_file(node.absolute_path)
|
self.explorer:focus_node_or_parent(node)
|
||||||
elseif last_node then
|
elseif last_node then
|
||||||
utils.focus_file(last_node.absolute_path)
|
self.explorer:focus_node_or_parent(last_node)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -233,7 +233,13 @@ local function reload_tree_at(toplevel)
|
|||||||
end
|
end
|
||||||
|
|
||||||
log.line("watcher", "git event executing '%s'", toplevel)
|
log.line("watcher", "git event executing '%s'", toplevel)
|
||||||
local root_node = utils.get_node_from_path(toplevel)
|
|
||||||
|
local explorer = require("nvim-tree.core").get_explorer()
|
||||||
|
if not explorer then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
local root_node = explorer:get_node_from_path(toplevel)
|
||||||
if not root_node then
|
if not root_node then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -252,7 +258,7 @@ local function reload_tree_at(toplevel)
|
|||||||
end)
|
end)
|
||||||
:iterate()
|
:iterate()
|
||||||
|
|
||||||
root_node.explorer.renderer:draw()
|
explorer.renderer:draw()
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -1,27 +1,74 @@
|
|||||||
local utils = require("nvim-tree.utils")
|
|
||||||
local notify = require("nvim-tree.notify")
|
local notify = require("nvim-tree.notify")
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
|
--- Create empty sub-tables if not present
|
||||||
|
---@param tbl table to create empty inside of
|
||||||
|
---@param path string dot separated string of sub-tables
|
||||||
|
---@return table deepest sub-table
|
||||||
|
local function create(tbl, path)
|
||||||
|
local t = tbl
|
||||||
|
for s in string.gmatch(path, "([^%.]+)%.*") do
|
||||||
|
if t[s] == nil then
|
||||||
|
t[s] = {}
|
||||||
|
end
|
||||||
|
t = t[s]
|
||||||
|
end
|
||||||
|
|
||||||
|
return t
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Move a value from src to dst if value is nil on dst.
|
||||||
|
--- Remove value from src
|
||||||
|
---@param src table to copy from
|
||||||
|
---@param src_path string dot separated string of sub-tables
|
||||||
|
---@param src_pos string value pos
|
||||||
|
---@param dst table to copy to
|
||||||
|
---@param dst_path string dot separated string of sub-tables, created when missing
|
||||||
|
---@param dst_pos string value pos
|
||||||
|
---@param remove boolean
|
||||||
|
local function move(src, src_path, src_pos, dst, dst_path, dst_pos, remove)
|
||||||
|
for pos in string.gmatch(src_path, "([^%.]+)%.*") do
|
||||||
|
if src[pos] and type(src[pos]) == "table" then
|
||||||
|
src = src[pos]
|
||||||
|
else
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local src_val = src[src_pos]
|
||||||
|
if src_val == nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
dst = create(dst, dst_path)
|
||||||
|
if dst[dst_pos] == nil then
|
||||||
|
dst[dst_pos] = src_val
|
||||||
|
end
|
||||||
|
|
||||||
|
if remove then
|
||||||
|
src[src_pos] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- silently move, please add to help nvim-tree-legacy-opts
|
-- silently move, please add to help nvim-tree-legacy-opts
|
||||||
local function refactored(opts)
|
local function refactored(opts)
|
||||||
-- 2022/06/20
|
-- 2022/06/20
|
||||||
utils.move_missing_val(opts, "update_focused_file", "update_cwd", opts, "update_focused_file", "update_root", true)
|
move(opts, "update_focused_file", "update_cwd", opts, "update_focused_file", "update_root", true)
|
||||||
utils.move_missing_val(opts, "", "update_cwd", opts, "", "sync_root_with_cwd", true)
|
move(opts, "", "update_cwd", opts, "", "sync_root_with_cwd", true)
|
||||||
|
|
||||||
-- 2022/11/07
|
-- 2022/11/07
|
||||||
utils.move_missing_val(opts, "", "open_on_tab", opts, "tab.sync", "open", false)
|
move(opts, "", "open_on_tab", opts, "tab.sync", "open", false)
|
||||||
utils.move_missing_val(opts, "", "open_on_tab", opts, "tab.sync", "close", true)
|
move(opts, "", "open_on_tab", opts, "tab.sync", "close", true)
|
||||||
utils.move_missing_val(opts, "", "ignore_buf_on_tab_change", opts, "tab.sync", "ignore", true)
|
move(opts, "", "ignore_buf_on_tab_change", opts, "tab.sync", "ignore", true)
|
||||||
|
|
||||||
-- 2022/11/22
|
-- 2022/11/22
|
||||||
utils.move_missing_val(opts, "renderer", "root_folder_modifier", opts, "renderer", "root_folder_label", true)
|
move(opts, "renderer", "root_folder_modifier", opts, "renderer", "root_folder_label", true)
|
||||||
|
|
||||||
-- 2023/01/01
|
-- 2023/01/01
|
||||||
utils.move_missing_val(opts, "update_focused_file", "debounce_delay", opts, "view", "debounce_delay", true)
|
move(opts, "update_focused_file", "debounce_delay", opts, "view", "debounce_delay", true)
|
||||||
|
|
||||||
-- 2023/01/08
|
-- 2023/01/08
|
||||||
utils.move_missing_val(opts, "trash", "require_confirm", opts, "ui.confirm", "trash", true)
|
move(opts, "trash", "require_confirm", opts, "ui.confirm", "trash", true)
|
||||||
|
|
||||||
-- 2023/01/15
|
-- 2023/01/15
|
||||||
if type(opts.view) == "table" and opts.view.adaptive_size ~= nil then
|
if type(opts.view) == "table" and opts.view.adaptive_size ~= nil then
|
||||||
@ -35,13 +82,13 @@ local function refactored(opts)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- 2023/07/15
|
-- 2023/07/15
|
||||||
utils.move_missing_val(opts, "", "sort_by", opts, "sort", "sorter", true)
|
move(opts, "", "sort_by", opts, "sort", "sorter", true)
|
||||||
|
|
||||||
-- 2023/07/16
|
-- 2023/07/16
|
||||||
utils.move_missing_val(opts, "git", "ignore", opts, "filters", "git_ignored", true)
|
move(opts, "git", "ignore", opts, "filters", "git_ignored", true)
|
||||||
|
|
||||||
-- 2023/08/26
|
-- 2023/08/26
|
||||||
utils.move_missing_val(opts, "renderer.icons", "webdev_colors", opts, "renderer.icons.web_devicons.file", "color", true)
|
move(opts, "renderer.icons", "webdev_colors", opts, "renderer.icons.web_devicons.file", "color", true)
|
||||||
|
|
||||||
-- 2023/10/08
|
-- 2023/10/08
|
||||||
if type(opts.renderer) == "table" and type(opts.renderer.highlight_diagnostics) == "boolean" then
|
if type(opts.renderer) == "table" and type(opts.renderer.highlight_diagnostics) == "boolean" then
|
||||||
@ -59,7 +106,7 @@ local function refactored(opts)
|
|||||||
opts.update_focused_file.update_root = { enable = opts.update_focused_file.update_root }
|
opts.update_focused_file.update_root = { enable = opts.update_focused_file.update_root }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
utils.move_missing_val(opts, "update_focused_file", "ignore_list", opts, "update_focused_file.update_root", "ignore_list", true)
|
move(opts, "update_focused_file", "ignore_list", opts, "update_focused_file.update_root", "ignore_list", true)
|
||||||
|
|
||||||
-- 2025/04/30
|
-- 2025/04/30
|
||||||
if opts.renderer and opts.renderer.icons and type(opts.renderer.icons.padding) == "string" then
|
if opts.renderer and opts.renderer.icons and type(opts.renderer.icons.padding) == "string" then
|
||||||
|
|||||||
@ -227,9 +227,9 @@ function Marks:navigate(up)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if up then
|
if up then
|
||||||
utils.focus_node_or_parent(prev or last)
|
self.explorer:focus_node_or_parent(prev or last)
|
||||||
else
|
else
|
||||||
utils.focus_node_or_parent(next or first)
|
self.explorer:focus_node_or_parent(next or first)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -263,7 +263,7 @@ function Marks:navigate_select()
|
|||||||
if node and not node:is(DirectoryNode) and not utils.get_win_buf_from_path(node.absolute_path) then
|
if node and not node:is(DirectoryNode) and not utils.get_win_buf_from_path(node.absolute_path) then
|
||||||
open_file.fn("edit", node.absolute_path)
|
open_file.fn("edit", node.absolute_path)
|
||||||
elseif node then
|
elseif node then
|
||||||
utils.focus_file(node.absolute_path)
|
self.explorer:focus_node_or_parent(node)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -101,7 +101,7 @@ end
|
|||||||
---@param end_ number|nil
|
---@param end_ number|nil
|
||||||
function Builder:insert_highlight(groups, start, end_)
|
function Builder:insert_highlight(groups, start, end_)
|
||||||
for _, higroup in ipairs(groups) do
|
for _, higroup in ipairs(groups) do
|
||||||
table.insert(self.hl_range_args, { higroup = higroup, start = { self.index, start, }, finish = { self.index, end_ or -1, } })
|
table.insert(self.hl_range_args, { higroup = higroup, start = { self.index, start }, finish = { self.index, end_ or -1 } })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -381,8 +381,28 @@ end
|
|||||||
function Builder:build_header()
|
function Builder:build_header()
|
||||||
if view.is_root_folder_visible(self.explorer.absolute_path) then
|
if view.is_root_folder_visible(self.explorer.absolute_path) then
|
||||||
local root_name = self:format_root_name(self.explorer.opts.renderer.root_folder_label)
|
local root_name = self:format_root_name(self.explorer.opts.renderer.root_folder_label)
|
||||||
table.insert(self.lines, root_name)
|
|
||||||
self:insert_highlight({ "NvimTreeRootFolder" }, 0, string.len(root_name))
|
-- Pad to window width so the highlight spans the whole row.
|
||||||
|
local win = view.get_winnr()
|
||||||
|
local width = 0
|
||||||
|
if win and vim.api.nvim_win_is_valid(win) then
|
||||||
|
width = vim.api.nvim_win_get_width(win)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Use display width for proper padding with Nerd Font / wide glyphs.
|
||||||
|
local name_display_w = vim.fn.strdisplaywidth(root_name)
|
||||||
|
local pad = 0
|
||||||
|
if width and width > name_display_w then
|
||||||
|
pad = width - name_display_w
|
||||||
|
end
|
||||||
|
|
||||||
|
local padded_root = pad > 0 and (root_name .. string.rep(" ", pad)) or root_name
|
||||||
|
|
||||||
|
table.insert(self.lines, padded_root)
|
||||||
|
-- Highlight the entire padded string (covers the full visible row)
|
||||||
|
self:insert_highlight({ "NvimTreeRootFolder" }, 0, string.len(padded_root))
|
||||||
|
|
||||||
|
-- Keep original indexing behavior
|
||||||
self.index = 1
|
self.index = 1
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -395,7 +415,6 @@ function Builder:build_header()
|
|||||||
self.index = self.index + 1
|
self.index = self.index + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---Sanitize lines for rendering.
|
---Sanitize lines for rendering.
|
||||||
---Replace newlines with literal \n
|
---Replace newlines with literal \n
|
||||||
---@private
|
---@private
|
||||||
@ -449,7 +468,8 @@ function Builder:setup_hidden_display_function(opts)
|
|||||||
local ok, result = pcall(hidden_display, hidden_stats)
|
local ok, result = pcall(hidden_display, hidden_stats)
|
||||||
if not ok then
|
if not ok then
|
||||||
notify.warn(
|
notify.warn(
|
||||||
"Problem occurred in the function ``opts.renderer.hidden_display`` see nvim-tree.renderer.hidden_display on :h nvim-tree")
|
"Problem occurred in the function ``opts.renderer.hidden_display`` see nvim-tree.renderer.hidden_display on :h nvim-tree"
|
||||||
|
)
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
return result
|
return result
|
||||||
|
|||||||
@ -22,8 +22,8 @@ local function check_siblings_for_folder(node, with_arrows)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function get_padding_indent_markers(depth, idx, nodes_number, markers, with_arrows, inline_arrows, node, early_stop)
|
local function get_padding_indent_markers(depth, idx, nodes_number, markers, with_arrows, inline_arrows, node, early_stop)
|
||||||
local base_padding = with_arrows and (not node.nodes or depth > 0) and " " or ""
|
local base_padding = with_arrows and (not node.nodes or depth > 0) and " " or " "
|
||||||
local padding = (inline_arrows or depth == 0) and base_padding or ""
|
local padding = (inline_arrows or depth == 0) and base_padding or " "
|
||||||
|
|
||||||
if depth > 0 then
|
if depth > 0 then
|
||||||
local has_folder_sibling = check_siblings_for_folder(node, with_arrows)
|
local has_folder_sibling = check_siblings_for_folder(node, with_arrows)
|
||||||
|
|||||||
@ -47,11 +47,23 @@ function DiagnosticsDecorator:new(args)
|
|||||||
self.highlight_range = self.explorer.opts.renderer.highlight_diagnostics or "none"
|
self.highlight_range = self.explorer.opts.renderer.highlight_diagnostics or "none"
|
||||||
self.icon_placement = self.explorer.opts.renderer.icons.diagnostics_placement or "none"
|
self.icon_placement = self.explorer.opts.renderer.icons.diagnostics_placement or "none"
|
||||||
|
|
||||||
|
local vim_diagnostic_icons = {}
|
||||||
|
|
||||||
|
if self.explorer.opts.diagnostics.diagnostic_opts then
|
||||||
|
local vim_diagnostic_config = vim.diagnostic.config() or {}
|
||||||
|
local signs = vim_diagnostic_config.signs or {}
|
||||||
|
if type(signs) == "function" then
|
||||||
|
signs = signs(0, 0)
|
||||||
|
end
|
||||||
|
|
||||||
|
vim_diagnostic_icons = (type(signs) == "table" and signs.text) or {}
|
||||||
|
end
|
||||||
|
|
||||||
if self.explorer.opts.renderer.icons.show.diagnostics then
|
if self.explorer.opts.renderer.icons.show.diagnostics then
|
||||||
self.diag_icons = {}
|
self.diag_icons = {}
|
||||||
for name, sev in pairs(ICON_KEYS) do
|
for name, sev in pairs(ICON_KEYS) do
|
||||||
self.diag_icons[sev] = {
|
self.diag_icons[sev] = {
|
||||||
str = self.explorer.opts.diagnostics.icons[name],
|
str = vim_diagnostic_icons[sev] or self.explorer.opts.diagnostics.icons[name],
|
||||||
hl = { HG_ICON[sev] },
|
hl = { HG_ICON[sev] },
|
||||||
}
|
}
|
||||||
self:define_sign(self.diag_icons[sev])
|
self:define_sign(self.diag_icons[sev])
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
local Iterator = require("nvim-tree.iterators.node-iterator")
|
|
||||||
|
|
||||||
local M = {
|
local M = {
|
||||||
debouncers = {},
|
debouncers = {},
|
||||||
}
|
}
|
||||||
@ -17,22 +15,6 @@ function M.str_find(haystack, needle)
|
|||||||
return vim.fn.stridx(haystack, needle) ~= -1
|
return vim.fn.stridx(haystack, needle) ~= -1
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param path string
|
|
||||||
---@return string|uv.uv_fs_t
|
|
||||||
function M.read_file(path)
|
|
||||||
local fd = vim.loop.fs_open(path, "r", 438)
|
|
||||||
if not fd then
|
|
||||||
return ""
|
|
||||||
end
|
|
||||||
local stat = vim.loop.fs_fstat(fd)
|
|
||||||
if not stat then
|
|
||||||
return ""
|
|
||||||
end
|
|
||||||
local data = vim.loop.fs_read(fd, stat.size, 0)
|
|
||||||
vim.loop.fs_close(fd)
|
|
||||||
return data or ""
|
|
||||||
end
|
|
||||||
|
|
||||||
local path_separator = package.config:sub(1, 1)
|
local path_separator = package.config:sub(1, 1)
|
||||||
---@param paths string[]
|
---@param paths string[]
|
||||||
---@return string
|
---@return string
|
||||||
@ -130,48 +112,6 @@ end
|
|||||||
|
|
||||||
M.path_separator = path_separator
|
M.path_separator = path_separator
|
||||||
|
|
||||||
--- Get the node and index of the node from the tree that matches the predicate.
|
|
||||||
--- The explored nodes are those displayed on the view.
|
|
||||||
---@param nodes Node[]
|
|
||||||
---@param fn fun(node: Node): boolean
|
|
||||||
---@return table|nil
|
|
||||||
---@return number
|
|
||||||
function M.find_node(nodes, fn)
|
|
||||||
local node, i = Iterator.builder(nodes)
|
|
||||||
:matcher(fn)
|
|
||||||
:recursor(function(node)
|
|
||||||
return node.group_next and { node.group_next } or (node.open and #node.nodes > 0 and node.nodes)
|
|
||||||
end)
|
|
||||||
:iterate()
|
|
||||||
i = require("nvim-tree.view").is_root_folder_visible() and i or i - 1
|
|
||||||
if node and node.explorer.live_filter.filter then
|
|
||||||
i = i + 1
|
|
||||||
end
|
|
||||||
return node, i
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Find the line number of a node.
|
|
||||||
-- Return -1 is node is nil or not found.
|
|
||||||
---@param node Node?
|
|
||||||
---@return integer
|
|
||||||
function M.find_node_line(node)
|
|
||||||
if not node then
|
|
||||||
return -1
|
|
||||||
end
|
|
||||||
|
|
||||||
local first_node_line = require("nvim-tree.core").get_nodes_starting_line()
|
|
||||||
local nodes_by_line = M.get_nodes_by_line(require("nvim-tree.core").get_explorer().nodes, first_node_line)
|
|
||||||
local iter_start, iter_end = first_node_line, #nodes_by_line
|
|
||||||
|
|
||||||
for line = iter_start, iter_end, 1 do
|
|
||||||
if nodes_by_line[line] == node then
|
|
||||||
return line
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return -1
|
|
||||||
end
|
|
||||||
|
|
||||||
---@param extmarks vim.api.keyset.get_extmark_item[] as per vim.api.nvim_buf_get_extmarks
|
---@param extmarks vim.api.keyset.get_extmark_item[] as per vim.api.nvim_buf_get_extmarks
|
||||||
---@return number
|
---@return number
|
||||||
function M.extmarks_length(extmarks)
|
function M.extmarks_length(extmarks)
|
||||||
@ -187,39 +127,6 @@ function M.extmarks_length(extmarks)
|
|||||||
return length
|
return length
|
||||||
end
|
end
|
||||||
|
|
||||||
-- get the node in the tree state depending on the absolute path of the node
|
|
||||||
-- (grouped or hidden too)
|
|
||||||
---@param path string
|
|
||||||
---@return Node|nil
|
|
||||||
---@return number|nil
|
|
||||||
function M.get_node_from_path(path)
|
|
||||||
local explorer = require("nvim-tree.core").get_explorer()
|
|
||||||
|
|
||||||
-- tree may not yet be loaded
|
|
||||||
if not explorer then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
if explorer.absolute_path == path then
|
|
||||||
return explorer
|
|
||||||
end
|
|
||||||
|
|
||||||
return Iterator.builder(explorer.nodes)
|
|
||||||
:hidden()
|
|
||||||
:matcher(function(node)
|
|
||||||
return node.absolute_path == path or node.link_to == path
|
|
||||||
end)
|
|
||||||
:recursor(function(node)
|
|
||||||
if node.group_next then
|
|
||||||
return { node.group_next }
|
|
||||||
end
|
|
||||||
if node.nodes then
|
|
||||||
return node.nodes
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
:iterate()
|
|
||||||
end
|
|
||||||
|
|
||||||
M.default_format_hidden_count = function(hidden_count, simple)
|
M.default_format_hidden_count = function(hidden_count, simple)
|
||||||
local parts = {}
|
local parts = {}
|
||||||
local total_count = 0
|
local total_count = 0
|
||||||
@ -240,30 +147,6 @@ M.default_format_hidden_count = function(hidden_count, simple)
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Return visible nodes indexed by line
|
|
||||||
---@param nodes_all Node[]
|
|
||||||
---@param line_start number
|
|
||||||
---@return table
|
|
||||||
function M.get_nodes_by_line(nodes_all, line_start)
|
|
||||||
local nodes_by_line = {}
|
|
||||||
local line = line_start
|
|
||||||
|
|
||||||
Iterator.builder(nodes_all)
|
|
||||||
:applier(function(node)
|
|
||||||
if node.group_next then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
nodes_by_line[line] = node
|
|
||||||
line = line + 1
|
|
||||||
end)
|
|
||||||
:recursor(function(node)
|
|
||||||
return node.group_next and { node.group_next } or (node.open and #node.nodes > 0 and node.nodes)
|
|
||||||
end)
|
|
||||||
:iterate()
|
|
||||||
|
|
||||||
return nodes_by_line
|
|
||||||
end
|
|
||||||
|
|
||||||
function M.rename_loaded_buffers(old_path, new_path)
|
function M.rename_loaded_buffers(old_path, new_path)
|
||||||
-- delete new if it exists
|
-- delete new if it exists
|
||||||
for _, buf in pairs(vim.api.nvim_list_bufs()) do
|
for _, buf in pairs(vim.api.nvim_list_bufs()) do
|
||||||
@ -377,54 +260,6 @@ function M.escape_special_chars(path)
|
|||||||
return M.is_windows and escape_special_char_for_windows(path) or path
|
return M.is_windows and escape_special_char_for_windows(path) or path
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Create empty sub-tables if not present
|
|
||||||
---@param tbl table to create empty inside of
|
|
||||||
---@param path string dot separated string of sub-tables
|
|
||||||
---@return table deepest sub-table
|
|
||||||
function M.table_create_missing(tbl, path)
|
|
||||||
local t = tbl
|
|
||||||
for s in string.gmatch(path, "([^%.]+)%.*") do
|
|
||||||
if t[s] == nil then
|
|
||||||
t[s] = {}
|
|
||||||
end
|
|
||||||
t = t[s]
|
|
||||||
end
|
|
||||||
|
|
||||||
return t
|
|
||||||
end
|
|
||||||
|
|
||||||
--- Move a value from src to dst if value is nil on dst.
|
|
||||||
--- Remove value from src
|
|
||||||
---@param src table to copy from
|
|
||||||
---@param src_path string dot separated string of sub-tables
|
|
||||||
---@param src_pos string value pos
|
|
||||||
---@param dst table to copy to
|
|
||||||
---@param dst_path string dot separated string of sub-tables, created when missing
|
|
||||||
---@param dst_pos string value pos
|
|
||||||
---@param remove boolean
|
|
||||||
function M.move_missing_val(src, src_path, src_pos, dst, dst_path, dst_pos, remove)
|
|
||||||
for pos in string.gmatch(src_path, "([^%.]+)%.*") do
|
|
||||||
if src[pos] and type(src[pos]) == "table" then
|
|
||||||
src = src[pos]
|
|
||||||
else
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
local src_val = src[src_pos]
|
|
||||||
if src_val == nil then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
dst = M.table_create_missing(dst, dst_path)
|
|
||||||
if dst[dst_pos] == nil then
|
|
||||||
dst[dst_pos] = src_val
|
|
||||||
end
|
|
||||||
|
|
||||||
if remove then
|
|
||||||
src[src_pos] = nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function round(value)
|
local function round(value)
|
||||||
-- Amount of digits to round to after floating point.
|
-- Amount of digits to round to after floating point.
|
||||||
local digits = 2
|
local digits = 2
|
||||||
@ -533,38 +368,6 @@ function M.debounce(context, timeout, callback)
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.focus_file(path)
|
|
||||||
local _, i = M.find_node(require("nvim-tree.core").get_explorer().nodes, function(node)
|
|
||||||
return node.absolute_path == path
|
|
||||||
end)
|
|
||||||
require("nvim-tree.view").set_cursor({ i + 1, 1 })
|
|
||||||
end
|
|
||||||
|
|
||||||
---Focus node passed as parameter if visible, otherwise focus first visible parent.
|
|
||||||
---If none of the parents is visible focus root.
|
|
||||||
---If node is nil do nothing.
|
|
||||||
---@param node Node? node to focus
|
|
||||||
function M.focus_node_or_parent(node)
|
|
||||||
local explorer = require("nvim-tree.core").get_explorer()
|
|
||||||
|
|
||||||
if explorer == nil then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
while node do
|
|
||||||
local found_node, i = M.find_node(explorer.nodes, function(node_)
|
|
||||||
return node_.absolute_path == node.absolute_path
|
|
||||||
end)
|
|
||||||
|
|
||||||
if found_node or node.parent == nil then
|
|
||||||
require("nvim-tree.view").set_cursor({ i + 1, 1 })
|
|
||||||
break
|
|
||||||
end
|
|
||||||
|
|
||||||
node = node.parent
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
---@param path string
|
---@param path string
|
||||||
---@return integer|nil
|
---@return integer|nil
|
||||||
---@return integer|nil
|
---@return integer|nil
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user