mirror of
https://github.com/nvim-tree/nvim-tree.lua.git
synced 2026-07-28 15:59:44 +05:30
Compare commits
13 Commits
8f73cbb7d2
...
3323
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c97f42044d | ||
|
|
4213bd6eab | ||
|
|
f2dd529e3f | ||
|
|
cf18a662cd | ||
|
|
a797d5e201 | ||
|
|
35d3511e7a | ||
|
|
7ff7040bf6 | ||
|
|
531b807b8f | ||
|
|
c760c92667 | ||
|
|
8e8be709c9 | ||
|
|
fb343438d4 | ||
|
|
82f58063d6 | ||
|
|
07f541fcaa |
6
.github/workflows/ci.yml
vendored
6
.github/workflows/ci.yml
vendored
@@ -5,6 +5,8 @@ on:
|
|||||||
push:
|
push:
|
||||||
branches: [master]
|
branches: [master]
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
schedule:
|
||||||
|
- cron: '0 0 * * 0' # weekly on sundays
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
@@ -24,7 +26,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: checkout
|
- name: checkout
|
||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v7
|
||||||
|
|
||||||
- name: install lua ${{ matrix.lua_version }}
|
- name: install lua ${{ matrix.lua_version }}
|
||||||
uses: leafo/gh-actions-lua@v13
|
uses: leafo/gh-actions-lua@v13
|
||||||
@@ -58,7 +60,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: checkout
|
- name: checkout
|
||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v7
|
||||||
|
|
||||||
- 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@v6
|
- uses: actions/checkout@v7
|
||||||
- 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: googleapis/release-please-action@v5
|
- uses: googleapis/release-please-action@v5
|
||||||
id: release
|
id: release
|
||||||
- uses: actions/checkout@v6
|
- uses: actions/checkout@v7
|
||||||
- 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: |
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
{
|
{
|
||||||
".": "1.17.0"
|
".": "1.18.0"
|
||||||
}
|
}
|
||||||
|
|||||||
15
CHANGELOG.md
15
CHANGELOG.md
@@ -1,5 +1,20 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## [1.18.0](https://github.com/nvim-tree/nvim-tree.lua/compare/nvim-tree-v1.17.0...nvim-tree-v1.18.0) (2026-07-01)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* **#1549:** p will paste files from another nvim-tree instance, gp will cut/paste ([#3336](https://github.com/nvim-tree/nvim-tree.lua/issues/3336)) ([c760c92](https://github.com/nvim-tree/nvim-tree.lua/commit/c760c92667fe5febf99e2a5bb8a543b0208c743b))
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* **#3312:** correct cursor when full name shown, requires nvim 0.12.2+ ([#3316](https://github.com/nvim-tree/nvim-tree.lua/issues/3316)) ([d277467](https://github.com/nvim-tree/nvim-tree.lua/commit/d277467fc0d1d0e2bca88165a1de6b526f9f6fe8))
|
||||||
|
* **#3324:** deprecated BufModifiedSet event replaced by OptionSet event for Nvim 0.13+ ([#3325](https://github.com/nvim-tree/nvim-tree.lua/issues/3325)) ([f9bfc00](https://github.com/nvim-tree/nvim-tree.lua/commit/f9bfc0059eca24546b69a7006110463da4808f8f))
|
||||||
|
* **#3327:** pass nvim_tree.api.node.open.Opts to all applicable nvim_tree.api.node.open function ([#3329](https://github.com/nvim-tree/nvim-tree.lua/issues/3329)) ([07f541f](https://github.com/nvim-tree/nvim-tree.lua/commit/07f541fcaa4a5ae019598240362449ab7e9812b3))
|
||||||
|
* **full-name:** lower `zindex` to get consistent cursor shape ([d277467](https://github.com/nvim-tree/nvim-tree.lua/commit/d277467fc0d1d0e2bca88165a1de6b526f9f6fe8))
|
||||||
|
|
||||||
## [1.17.0](https://github.com/nvim-tree/nvim-tree.lua/compare/nvim-tree-v1.16.0...nvim-tree-v1.17.0) (2026-04-07)
|
## [1.17.0](https://github.com/nvim-tree/nvim-tree.lua/compare/nvim-tree-v1.16.0...nvim-tree-v1.17.0) (2026-04-07)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,9 @@
|
|||||||
|
|
||||||
(Live) filtering
|
(Live) filtering
|
||||||
|
|
||||||
Cut, copy, paste, rename, delete, create
|
Rename, delete, create
|
||||||
|
|
||||||
|
Cut, copy, paste locally and between instances
|
||||||
|
|
||||||
Highly customisable
|
Highly customisable
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -59,13 +59,25 @@ function nvim_tree.api.fs.create(node) end
|
|||||||
function nvim_tree.api.fs.cut(node) end
|
function nvim_tree.api.fs.cut(node) end
|
||||||
|
|
||||||
---
|
---
|
||||||
---Paste from the nvim-tree clipboard.
|
---Paste files from:
|
||||||
|
---- current nvim-tree clipboard (if present)
|
||||||
|
---- another nvim-tree instance via system clipboard
|
||||||
---
|
---
|
||||||
---If {node} is a file it will pasted in the parent directory.
|
---If {node} is a file it will pasted in the parent directory.
|
||||||
---
|
---
|
||||||
---@param node? nvim_tree.api.Node
|
---@param node? nvim_tree.api.Node
|
||||||
function nvim_tree.api.fs.paste(node) end
|
function nvim_tree.api.fs.paste(node) end
|
||||||
|
|
||||||
|
---
|
||||||
|
---Paste while cutting files from:
|
||||||
|
---- current nvim-tree clipboard (if present)
|
||||||
|
---- another nvim-tree instance via system clipboard
|
||||||
|
---
|
||||||
|
---If {node} is a file it will pasted in the parent directory.
|
||||||
|
---
|
||||||
|
---@param node? nvim_tree.api.Node
|
||||||
|
function nvim_tree.api.fs.move(node) end
|
||||||
|
|
||||||
---
|
---
|
||||||
---Print the contents of the nvim-tree clipboard.
|
---Print the contents of the nvim-tree clipboard.
|
||||||
---
|
---
|
||||||
|
|||||||
@@ -16,6 +16,12 @@ nvim_tree.api.node.open = {}
|
|||||||
---@field focus? boolean
|
---@field focus? boolean
|
||||||
|
|
||||||
|
|
||||||
|
---
|
||||||
|
---Switch to window with selected file if it exists, otherwise open, see [:drop]
|
||||||
|
---
|
||||||
|
---@param node? nvim_tree.api.Node directory or file
|
||||||
|
function nvim_tree.api.node.open.drop(node) end
|
||||||
|
|
||||||
---
|
---
|
||||||
---- file: open as per [nvim_tree.config.actions.open_file]
|
---- file: open as per [nvim_tree.config.actions.open_file]
|
||||||
---- directory: expand or collapse
|
---- directory: expand or collapse
|
||||||
@@ -29,31 +35,36 @@ function nvim_tree.api.node.open.edit(node, opts) end
|
|||||||
---Open file in a new horizontal split.
|
---Open file in a new horizontal split.
|
||||||
---
|
---
|
||||||
---@param node? nvim_tree.api.Node file
|
---@param node? nvim_tree.api.Node file
|
||||||
function nvim_tree.api.node.open.horizontal(node) end
|
---@param opts? nvim_tree.api.node.open.Opts optional
|
||||||
|
function nvim_tree.api.node.open.horizontal(node, opts) end
|
||||||
|
|
||||||
---
|
---
|
||||||
---Open file in a new horizontal split without using the window picker.
|
---Open file in a new horizontal split without using the window picker.
|
||||||
---
|
---
|
||||||
---@param node? nvim_tree.api.Node file
|
---@param node? nvim_tree.api.Node file
|
||||||
function nvim_tree.api.node.open.horizontal_no_picker(node) end
|
---@param opts? nvim_tree.api.node.open.Opts optional
|
||||||
|
function nvim_tree.api.node.open.horizontal_no_picker(node, opts) end
|
||||||
|
|
||||||
---
|
---
|
||||||
---Open file without using the window picker.
|
---Open file without using the window picker.
|
||||||
---
|
---
|
||||||
---@param node? nvim_tree.api.Node file
|
---@param node? nvim_tree.api.Node file
|
||||||
function nvim_tree.api.node.open.no_window_picker(node) end
|
---@param opts? nvim_tree.api.node.open.Opts optional
|
||||||
|
function nvim_tree.api.node.open.no_window_picker(node, opts) end
|
||||||
|
|
||||||
---
|
---
|
||||||
---Open file with ['bufhidden'] set to `delete`.
|
---Open file with ['bufhidden'] set to `delete`.
|
||||||
---
|
---
|
||||||
---@param node? nvim_tree.api.Node directory or file
|
---@param node? nvim_tree.api.Node directory or file
|
||||||
function nvim_tree.api.node.open.preview(node) end
|
---@param opts? nvim_tree.api.node.open.Opts optional
|
||||||
|
function nvim_tree.api.node.open.preview(node, opts) end
|
||||||
|
|
||||||
---
|
---
|
||||||
---Open file with ['bufhidden'] set to `delete` without using the window picker.
|
---Open file with ['bufhidden'] set to `delete` without using the window picker.
|
||||||
---
|
---
|
||||||
---@param node? nvim_tree.api.Node directory or file
|
---@param node? nvim_tree.api.Node directory or file
|
||||||
function nvim_tree.api.node.open.preview_no_picker(node) end
|
---@param opts? nvim_tree.api.node.open.Opts optional
|
||||||
|
function nvim_tree.api.node.open.preview_no_picker(node, opts) end
|
||||||
|
|
||||||
---
|
---
|
||||||
---Open file in place: in the nvim-tree window.
|
---Open file in place: in the nvim-tree window.
|
||||||
@@ -65,10 +76,11 @@ function nvim_tree.api.node.open.replace_tree_buffer(node) end
|
|||||||
---Open file in a new tab.
|
---Open file in a new tab.
|
||||||
---
|
---
|
||||||
---@param node? nvim_tree.api.Node directory or file
|
---@param node? nvim_tree.api.Node directory or file
|
||||||
function nvim_tree.api.node.open.tab(node) end
|
---@param opts? nvim_tree.api.node.open.Opts optional
|
||||||
|
function nvim_tree.api.node.open.tab(node, opts) end
|
||||||
|
|
||||||
---
|
---
|
||||||
---Switch to tab containing window with selected file if it exists. Open file in new tab otherwise.
|
---Switch to tab containing window with selected file if it exists, otherwise open in new tab, see [:drop]
|
||||||
---
|
---
|
||||||
---@param node? nvim_tree.api.Node directory or file
|
---@param node? nvim_tree.api.Node directory or file
|
||||||
function nvim_tree.api.node.open.tab_drop(node) end
|
function nvim_tree.api.node.open.tab_drop(node) end
|
||||||
@@ -83,13 +95,15 @@ function nvim_tree.api.node.open.toggle_group_empty(node) end
|
|||||||
---Open file in a new vertical split.
|
---Open file in a new vertical split.
|
||||||
---
|
---
|
||||||
---@param node? nvim_tree.api.Node file
|
---@param node? nvim_tree.api.Node file
|
||||||
function nvim_tree.api.node.open.vertical(node) end
|
---@param opts? nvim_tree.api.node.open.Opts optional
|
||||||
|
function nvim_tree.api.node.open.vertical(node, opts) end
|
||||||
|
|
||||||
---
|
---
|
||||||
---Open file in a new vertical split without using the window picker.
|
---Open file in a new vertical split without using the window picker.
|
||||||
---
|
---
|
||||||
---@param node? nvim_tree.api.Node file
|
---@param node? nvim_tree.api.Node file
|
||||||
function nvim_tree.api.node.open.vertical_no_picker(node) end
|
---@param opts? nvim_tree.api.node.open.Opts optional
|
||||||
|
function nvim_tree.api.node.open.vertical_no_picker(node, opts) end
|
||||||
|
|
||||||
---
|
---
|
||||||
---@class nvim_tree.api.node.buffer.RemoveOpts
|
---@class nvim_tree.api.node.buffer.RemoveOpts
|
||||||
|
|||||||
@@ -9,6 +9,9 @@ error("Cannot require a meta file")
|
|||||||
---
|
---
|
||||||
---@class nvim_tree.config.experimental
|
---@class nvim_tree.config.experimental
|
||||||
---
|
---
|
||||||
|
---Restore nvim-tree buffers when restoring vim sessions (requires 0.13+).
|
||||||
|
---(default: `false`)
|
||||||
|
---@field session_restore_nvim? boolean
|
||||||
--Example below for future reference:
|
--Example below for future reference:
|
||||||
--
|
--
|
||||||
--Buffers opened by nvim-tree will use with relative paths instead of absolute.
|
--Buffers opened by nvim-tree will use with relative paths instead of absolute.
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ error("Cannot require a meta file")
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
---Filters may be applied to the tree to exlude the display of file/directories.
|
---Filters may be applied to the tree to exclude the display of file/directories.
|
||||||
---
|
---
|
||||||
---Multiple filters may be applied at once.
|
---Multiple filters may be applied at once.
|
||||||
---
|
---
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ local find_file = require("nvim-tree.actions.finders.find-file").fn
|
|||||||
|
|
||||||
local Class = require("nvim-tree.classic")
|
local Class = require("nvim-tree.classic")
|
||||||
local DirectoryNode = require("nvim-tree.node.directory")
|
local DirectoryNode = require("nvim-tree.node.directory")
|
||||||
|
local FileNode = require("nvim-tree.node.file")
|
||||||
local Node = require("nvim-tree.node")
|
local Node = require("nvim-tree.node")
|
||||||
|
|
||||||
---@alias ClipboardAction "copy" | "cut"
|
---@alias ClipboardAction "copy" | "cut"
|
||||||
@@ -176,28 +177,40 @@ function Clipboard:bulk_clipboard(nodes, from, to, verb)
|
|||||||
self.explorer.renderer:draw()
|
self.explorer.renderer:draw()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@private
|
||||||
|
---@param node_or_nodes Node|Node[]
|
||||||
|
---@return boolean
|
||||||
|
function Clipboard:is_nodes_array(node_or_nodes)
|
||||||
|
if type(node_or_nodes) == "table" and node_or_nodes.is and node_or_nodes:is(Node) then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
---Copy one or more nodes
|
---Copy one or more nodes
|
||||||
---@param node_or_nodes Node|Node[]
|
---@param node_or_nodes Node|Node[]
|
||||||
function Clipboard:copy(node_or_nodes)
|
function Clipboard:copy(node_or_nodes)
|
||||||
if type(node_or_nodes) == "table" and node_or_nodes.is and node_or_nodes:is(Node) then
|
if self:is_nodes_array(node_or_nodes) == false then
|
||||||
utils.array_remove(self.data.cut, node_or_nodes)
|
utils.array_remove(self.data.cut, node_or_nodes)
|
||||||
toggle(node_or_nodes, self.data.copy)
|
toggle(node_or_nodes, self.data.copy)
|
||||||
self.explorer.renderer:draw()
|
self.explorer.renderer:draw()
|
||||||
else
|
else
|
||||||
self:bulk_clipboard(utils.filter_descendant_nodes(node_or_nodes), self.data.cut, self.data.copy, "added to")
|
self:bulk_clipboard(utils.filter_descendant_nodes(node_or_nodes), self.data.cut, self.data.copy, "added to")
|
||||||
end
|
end
|
||||||
|
self:copy_absolute_path(self.data.copy, { notify = false })
|
||||||
end
|
end
|
||||||
|
|
||||||
---Cut one or more nodes
|
---Cut one or more nodes
|
||||||
---@param node_or_nodes Node|Node[]
|
---@param node_or_nodes Node|Node[]
|
||||||
function Clipboard:cut(node_or_nodes)
|
function Clipboard:cut(node_or_nodes)
|
||||||
if type(node_or_nodes) == "table" and node_or_nodes.is and node_or_nodes:is(Node) then
|
if self:is_nodes_array(node_or_nodes) == false then
|
||||||
utils.array_remove(self.data.copy, node_or_nodes)
|
utils.array_remove(self.data.copy, node_or_nodes)
|
||||||
toggle(node_or_nodes, self.data.cut)
|
toggle(node_or_nodes, self.data.cut)
|
||||||
self.explorer.renderer:draw()
|
self.explorer.renderer:draw()
|
||||||
else
|
else
|
||||||
self:bulk_clipboard(utils.filter_descendant_nodes(node_or_nodes), self.data.copy, self.data.cut, "cut to")
|
self:bulk_clipboard(utils.filter_descendant_nodes(node_or_nodes), self.data.copy, self.data.cut, "cut to")
|
||||||
end
|
end
|
||||||
|
self:copy_absolute_path(self.data.cut, { notify = false })
|
||||||
end
|
end
|
||||||
|
|
||||||
---Clear clipboard for action and reload to reflect filesystem changes from paste.
|
---Clear clipboard for action and reload to reflect filesystem changes from paste.
|
||||||
@@ -304,6 +317,40 @@ function Clipboard:resolve_conflicts(conflict, destination, action, action_fn)
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Transforms the copied absolute paths on register to node
|
||||||
|
---@private
|
||||||
|
function Clipboard:get_nodes_from_reg()
|
||||||
|
local content = vim.fn.getreg(self.reg)
|
||||||
|
|
||||||
|
if #content == 0 then
|
||||||
|
return {}
|
||||||
|
end
|
||||||
|
|
||||||
|
local nodes = {}
|
||||||
|
local absolute_paths = vim.split(content:sub(1, #content), "\n")
|
||||||
|
|
||||||
|
for _, absolute_path in ipairs(absolute_paths) do
|
||||||
|
if absolute_path:match("^%s*(.-)%s*s") then
|
||||||
|
local node_args = { absolute_path = absolute_path, name = vim.fn.fnamemodify(absolute_path, ":t"), explorer = self.explorer }
|
||||||
|
if absolute_path:sub(-1) == "/" then
|
||||||
|
node_args.name = vim.fn.fnamemodify(absolute_path:sub(1, -2), ":t")
|
||||||
|
table.insert(nodes, DirectoryNode(node_args))
|
||||||
|
else
|
||||||
|
table.insert(nodes, FileNode(node_args))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return nodes
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param nodes Node[]
|
||||||
|
---@private
|
||||||
|
function Clipboard:destroy_nodes(nodes)
|
||||||
|
for _, n in ipairs(nodes) do
|
||||||
|
n:destroy()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
---Paste cut or copy with batch conflict resolution.
|
---Paste cut or copy with batch conflict resolution.
|
||||||
---@private
|
---@private
|
||||||
---@param node Node
|
---@param node Node
|
||||||
@@ -318,7 +365,9 @@ function Clipboard:do_paste(node, action, action_fn)
|
|||||||
node = dir:last_group_node()
|
node = dir:last_group_node()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local clip = self.data[action]
|
local is_local = #self.data[action] > 0
|
||||||
|
local clip = is_local and self.data[action] or self:get_nodes_from_reg()
|
||||||
|
|
||||||
if #clip == 0 then
|
if #clip == 0 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -328,6 +377,9 @@ function Clipboard:do_paste(node, action, action_fn)
|
|||||||
if not stats and err_name ~= "ENOENT" then
|
if not stats and err_name ~= "ENOENT" then
|
||||||
log.line("copy_paste", "do_paste fs_stat '%s' failed '%s'", destination, err)
|
log.line("copy_paste", "do_paste fs_stat '%s' failed '%s'", destination, err)
|
||||||
notify.error("Could not " .. action .. " " .. notify.render_path(destination) .. " - " .. (err or "???"))
|
notify.error("Could not " .. action .. " " .. notify.render_path(destination) .. " - " .. (err or "???"))
|
||||||
|
if is_local == false then
|
||||||
|
self:destroy_nodes(clip)
|
||||||
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local is_dir = stats and stats.type == "directory"
|
local is_dir = stats and stats.type == "directory"
|
||||||
@@ -359,6 +411,10 @@ function Clipboard:do_paste(node, action, action_fn)
|
|||||||
else
|
else
|
||||||
self:finish_paste(action)
|
self:finish_paste(action)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if is_local == false then
|
||||||
|
self:destroy_nodes(clip)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param source string
|
---@param source string
|
||||||
@@ -386,10 +442,12 @@ end
|
|||||||
|
|
||||||
---Paste cut (if present) or copy (if present)
|
---Paste cut (if present) or copy (if present)
|
||||||
---@param node Node
|
---@param node Node
|
||||||
function Clipboard:paste(node)
|
---@param opts? { cut?: boolean }
|
||||||
if self.data.cut[1] ~= nil then
|
function Clipboard:paste(node, opts)
|
||||||
|
opts = opts and opts or {}
|
||||||
|
if self.data.cut[1] ~= nil or opts.cut == true then
|
||||||
self:do_paste(node, "cut", do_cut)
|
self:do_paste(node, "cut", do_cut)
|
||||||
elseif self.data.copy[1] ~= nil then
|
else
|
||||||
self:do_paste(node, "copy", do_copy)
|
self:do_paste(node, "copy", do_copy)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -413,17 +471,15 @@ function Clipboard:print_clipboard()
|
|||||||
end
|
end
|
||||||
|
|
||||||
---@param content string
|
---@param content string
|
||||||
function Clipboard:copy_to_reg(content)
|
---@param message? string
|
||||||
-- manually firing TextYankPost does not set vim.v.event
|
---@param opts? { notify?: boolean }
|
||||||
-- workaround: create a scratch buffer with the clipboard contents and send a yank command
|
function Clipboard:copy_to_reg(content, message, opts)
|
||||||
local temp_buf = vim.api.nvim_create_buf(false, true)
|
opts = opts and opts or {}
|
||||||
vim.api.nvim_buf_set_text(temp_buf, 0, 0, 0, 0, { content })
|
vim.fn.setreg(self.reg, type(content) == "table" and content or { content }, "v")
|
||||||
vim.api.nvim_buf_call(temp_buf, function()
|
|
||||||
vim.cmd(string.format('normal! "%sy$', self.reg))
|
|
||||||
end)
|
|
||||||
vim.api.nvim_buf_delete(temp_buf, {})
|
|
||||||
|
|
||||||
notify.info(string.format("Copied %s to %s clipboard!", content, self.clipboard_name))
|
if opts.notify ~= false then
|
||||||
|
notify.info(message or string.format("Copied %s to %s clipboard!", content, self.clipboard_name))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param node Node
|
---@param node Node
|
||||||
@@ -437,18 +493,20 @@ function Clipboard:copy_filename(node)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@private
|
||||||
---@param node Node
|
---@param node Node
|
||||||
function Clipboard:copy_basename(node)
|
---@return string
|
||||||
|
function Clipboard:get_absolute_path(node)
|
||||||
if node.name == ".." then
|
if node.name == ".." then
|
||||||
-- root
|
node = self.explorer
|
||||||
self:copy_to_reg(vim.fn.fnamemodify(self.explorer.absolute_path, ":t:r"))
|
|
||||||
else
|
|
||||||
-- node
|
|
||||||
self:copy_to_reg(vim.fn.fnamemodify(node.name, ":r"))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local absolute_path = node.absolute_path
|
||||||
|
return node.nodes ~= nil and utils.path_add_trailing(absolute_path) or absolute_path
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param node Node
|
---@param node Node
|
||||||
|
---@return string|nil
|
||||||
function Clipboard:copy_path(node)
|
function Clipboard:copy_path(node)
|
||||||
if node.name == ".." then
|
if node.name == ".." then
|
||||||
-- root
|
-- root
|
||||||
@@ -470,15 +528,44 @@ function Clipboard:copy_path(node)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param node Node
|
---@param node_or_nodes Node|Node[]
|
||||||
function Clipboard:copy_absolute_path(node)
|
---@param opts? { notify?: boolean }
|
||||||
if node.name == ".." then
|
function Clipboard:copy_absolute_path(node_or_nodes, opts)
|
||||||
node = self.explorer
|
opts = opts and opts or {}
|
||||||
|
local content
|
||||||
|
|
||||||
|
local is_single = self:is_nodes_array(node_or_nodes) == false
|
||||||
|
if is_single then
|
||||||
|
local node = #node_or_nodes == 1 and node_or_nodes[0] or node_or_nodes
|
||||||
|
content = self:get_absolute_path(node)
|
||||||
|
else
|
||||||
|
node_or_nodes = utils.filter_descendant_nodes(node_or_nodes)
|
||||||
|
content = {}
|
||||||
|
for _, node in ipairs(node_or_nodes) do
|
||||||
|
table.insert(content, self:get_absolute_path(node))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local absolute_path = node.absolute_path
|
|
||||||
local content = node.nodes ~= nil and utils.path_add_trailing(absolute_path) or absolute_path
|
if content ~= nil then
|
||||||
self:copy_to_reg(content)
|
local message = nil
|
||||||
|
|
||||||
|
if not is_single then
|
||||||
|
message = string.format("%s %s copied to register", #content, #content > 1 and "absolute paths" or "absolute path")
|
||||||
|
end
|
||||||
|
self:copy_to_reg(content, message, opts)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param node Node
|
||||||
|
function Clipboard:copy_basename(node)
|
||||||
|
if node.name == ".." then
|
||||||
|
-- root
|
||||||
|
self:copy_to_reg(vim.fn.fnamemodify(node.explorer.absolute_path, ":t:r"))
|
||||||
|
else
|
||||||
|
-- node
|
||||||
|
self:copy_to_reg(vim.fn.fnamemodify(node.name, ":r"))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---Node is cut. Will not be copied.
|
---Node is cut. Will not be copied.
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ function M.fn(node)
|
|||||||
local containing_folder = utils.path_add_trailing(dir.absolute_path)
|
local containing_folder = utils.path_add_trailing(dir.absolute_path)
|
||||||
|
|
||||||
local input_opts = {
|
local input_opts = {
|
||||||
prompt = "Create file ",
|
prompt = "Create ",
|
||||||
default = containing_folder,
|
default = containing_folder,
|
||||||
completion = "file",
|
completion = "file",
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,10 +11,6 @@ local DirectoryNode = require("nvim-tree.node.directory")
|
|||||||
local FileLinkNode = require("nvim-tree.node.file-link")
|
local FileLinkNode = require("nvim-tree.node.file-link")
|
||||||
local RootNode = require("nvim-tree.node.root")
|
local RootNode = require("nvim-tree.node.root")
|
||||||
|
|
||||||
---@class NodeEditOpts
|
|
||||||
---@field quit_on_open boolean|nil default false
|
|
||||||
---@field focus boolean|nil default true
|
|
||||||
|
|
||||||
---@alias NodeOpenFileMode ""|"change_dir"|"drop"|"edit"|"edit_in_place"|"edit_no_picker"|"preview"|"preview_no_picker"|"split"|"split_no_picker"|"tab_drop"|"tabnew"|"toggle_group_empty"|"vsplit"|"vsplit_no_picker"
|
---@alias NodeOpenFileMode ""|"change_dir"|"drop"|"edit"|"edit_in_place"|"edit_no_picker"|"preview"|"preview_no_picker"|"split"|"split_no_picker"|"tab_drop"|"tabnew"|"toggle_group_empty"|"vsplit"|"vsplit_no_picker"
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
@@ -422,7 +418,7 @@ end
|
|||||||
|
|
||||||
---@param mode string
|
---@param mode string
|
||||||
---@param node Node
|
---@param node Node
|
||||||
---@param edit_opts NodeEditOpts?
|
---@param edit_opts nvim_tree.api.node.open.Opts?
|
||||||
local function edit(mode, node, edit_opts)
|
local function edit(mode, node, edit_opts)
|
||||||
local file_link = node:as(FileLinkNode)
|
local file_link = node:as(FileLinkNode)
|
||||||
local path = file_link and file_link.link_to or node.absolute_path
|
local path = file_link and file_link.link_to or node.absolute_path
|
||||||
@@ -438,7 +434,7 @@ local function edit(mode, node, edit_opts)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local mode_unsupported_focus = mode == "drop" or mode == "tab_drop" or mode == "edit_in_place"
|
local mode_unsupported_focus = mode == "drop" or mode == "tab_drop" or mode == "edit_in_place"
|
||||||
local focus = edit_opts.focus == nil or edit_opts.focus == true
|
local focus = edit_opts.focus == nil or edit_opts.focus == false
|
||||||
if not mode_unsupported_focus and not focus then
|
if not mode_unsupported_focus and not focus then
|
||||||
-- if mode == "tabnew" a new tab will be opened and we need to focus back to the previous tab
|
-- if mode == "tabnew" a new tab will be opened and we need to focus back to the previous tab
|
||||||
if mode == "tabnew" then
|
if mode == "tabnew" then
|
||||||
@@ -451,7 +447,7 @@ end
|
|||||||
---@param node Node
|
---@param node Node
|
||||||
---@param mode NodeOpenFileMode
|
---@param mode NodeOpenFileMode
|
||||||
---@param toggle_group boolean?
|
---@param toggle_group boolean?
|
||||||
---@param edit_opts NodeEditOpts?
|
---@param edit_opts nvim_tree.api.node.open.Opts?
|
||||||
local function open_or_expand_or_dir_up(node, mode, toggle_group, edit_opts)
|
local function open_or_expand_or_dir_up(node, mode, toggle_group, edit_opts)
|
||||||
local root = node:as(RootNode)
|
local root = node:as(RootNode)
|
||||||
local dir = node:as(DirectoryNode)
|
local dir = node:as(DirectoryNode)
|
||||||
@@ -474,18 +470,21 @@ function M.toggle_group_empty(node)
|
|||||||
end
|
end
|
||||||
|
|
||||||
---@param node Node
|
---@param node Node
|
||||||
function M.preview(node)
|
---@param opts nvim_tree.api.node.open.Opts?
|
||||||
open_or_expand_or_dir_up(node, "preview")
|
function M.preview(node, opts)
|
||||||
|
open_or_expand_or_dir_up(node, "preview", false, opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param node Node
|
---@param node Node
|
||||||
function M.preview_no_picker(node)
|
---@param opts nvim_tree.api.node.open.Opts?
|
||||||
open_or_expand_or_dir_up(node, "preview_no_picker")
|
function M.preview_no_picker(node, opts)
|
||||||
|
open_or_expand_or_dir_up(node, "preview_no_picker", false, opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param node Node
|
---@param node Node
|
||||||
function M.edit(node)
|
---@param opts nvim_tree.api.node.open.Opts?
|
||||||
open_or_expand_or_dir_up(node, "edit")
|
function M.edit(node, opts)
|
||||||
|
open_or_expand_or_dir_up(node, "edit", false, opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param node Node
|
---@param node Node
|
||||||
@@ -504,33 +503,39 @@ function M.replace_tree_buffer(node)
|
|||||||
end
|
end
|
||||||
|
|
||||||
---@param node Node
|
---@param node Node
|
||||||
function M.no_window_picker(node)
|
---@param opts nvim_tree.api.node.open.Opts?
|
||||||
open_or_expand_or_dir_up(node, "edit_no_picker")
|
function M.no_window_picker(node, opts)
|
||||||
|
open_or_expand_or_dir_up(node, "edit_no_picker", false, opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param node Node
|
---@param node Node
|
||||||
function M.vertical(node)
|
---@param opts nvim_tree.api.node.open.Opts?
|
||||||
open_or_expand_or_dir_up(node, "vsplit")
|
function M.vertical(node, opts)
|
||||||
|
open_or_expand_or_dir_up(node, "vsplit", false, opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param node Node
|
---@param node Node
|
||||||
function M.vertical_no_picker(node)
|
---@param opts nvim_tree.api.node.open.Opts?
|
||||||
open_or_expand_or_dir_up(node, "vsplit_no_picker")
|
function M.vertical_no_picker(node, opts)
|
||||||
|
open_or_expand_or_dir_up(node, "vsplit_no_picker", false, opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param node Node
|
---@param node Node
|
||||||
function M.horizontal(node)
|
---@param opts nvim_tree.api.node.open.Opts?
|
||||||
open_or_expand_or_dir_up(node, "split")
|
function M.horizontal(node, opts)
|
||||||
|
open_or_expand_or_dir_up(node, "split", false, opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param node Node
|
---@param node Node
|
||||||
function M.horizontal_no_picker(node)
|
---@param opts nvim_tree.api.node.open.Opts?
|
||||||
open_or_expand_or_dir_up(node, "split_no_picker")
|
function M.horizontal_no_picker(node, opts)
|
||||||
|
open_or_expand_or_dir_up(node, "split_no_picker", false, opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param node Node
|
---@param node Node
|
||||||
function M.tab(node)
|
---@param opts nvim_tree.api.node.open.Opts?
|
||||||
open_or_expand_or_dir_up(node, "tabnew")
|
function M.tab(node, opts)
|
||||||
|
open_or_expand_or_dir_up(node, "tabnew", false, opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
local view = require("nvim-tree.view")
|
local view = require("nvim-tree.view")
|
||||||
|
local view_state = require("nvim-tree.view-state")
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
@@ -7,7 +8,7 @@ local M = {}
|
|||||||
function M.fn(opts)
|
function M.fn(opts)
|
||||||
if opts == nil then
|
if opts == nil then
|
||||||
-- reset to config values
|
-- reset to config values
|
||||||
view.configure_width()
|
view_state.configure_width()
|
||||||
view.resize()
|
view.resize()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -16,7 +17,7 @@ function M.fn(opts)
|
|||||||
local width_cfg = options.width
|
local width_cfg = options.width
|
||||||
|
|
||||||
if width_cfg ~= nil then
|
if width_cfg ~= nil then
|
||||||
view.configure_width(width_cfg)
|
view_state.configure_width(width_cfg)
|
||||||
view.resize()
|
view.resize()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -136,6 +136,11 @@ end
|
|||||||
---Called explicitly after nvim-tree setup
|
---Called explicitly after nvim-tree setup
|
||||||
---@param api table not properly typed to prevent LSP from referencing implementations
|
---@param api table not properly typed to prevent LSP from referencing implementations
|
||||||
function M.hydrate_post_setup(api)
|
function M.hydrate_post_setup(api)
|
||||||
|
-- Parameter naming conventions:
|
||||||
|
-- `e` explorer
|
||||||
|
-- `n` node
|
||||||
|
-- `o` opts
|
||||||
|
|
||||||
api.config.global = __(function() return require("nvim-tree.config").g_clone() end)
|
api.config.global = __(function() return require("nvim-tree.config").g_clone() end)
|
||||||
api.config.user = __(function() return require("nvim-tree.config").u_clone() end)
|
api.config.user = __(function() return require("nvim-tree.config").u_clone() end)
|
||||||
|
|
||||||
@@ -150,14 +155,15 @@ function M.hydrate_post_setup(api)
|
|||||||
api.filter.toggle = e_(function(e) e.filters:toggle() end)
|
api.filter.toggle = e_(function(e) e.filters:toggle() end)
|
||||||
|
|
||||||
api.fs.clear_clipboard = e_(function(e) e.clipboard:clear_clipboard() end)
|
api.fs.clear_clipboard = e_(function(e) e.clipboard:clear_clipboard() end)
|
||||||
api.fs.copy.absolute_path = en(function(e, n) e.clipboard:copy_absolute_path(n) end)
|
api.fs.copy.absolute_path = ev(function(e, n) e.clipboard:copy_absolute_path(n) end)
|
||||||
api.fs.copy.basename = en(function(e, n) e.clipboard:copy_basename(n) end)
|
api.fs.copy.basename = en(function(e, n) e.clipboard:copy_basename(n) end)
|
||||||
api.fs.copy.filename = en(function(e, n) e.clipboard:copy_filename(n) end)
|
api.fs.copy.filename = en(function(e, n) e.clipboard:copy_filename(n) end)
|
||||||
api.fs.copy.node = ev(function(e, n) e.clipboard:copy(n) end)
|
|
||||||
api.fs.copy.relative_path = en(function(e, n) e.clipboard:copy_path(n) end)
|
api.fs.copy.relative_path = en(function(e, n) e.clipboard:copy_path(n) end)
|
||||||
|
api.fs.copy.node = ev(function(e, n) e.clipboard:copy(n) end)
|
||||||
api.fs.create = _n(function(n) require("nvim-tree.actions.fs.create-file").fn(n) end)
|
api.fs.create = _n(function(n) require("nvim-tree.actions.fs.create-file").fn(n) end)
|
||||||
api.fs.cut = ev(function(e, n) e.clipboard:cut(n) end)
|
api.fs.cut = ev(function(e, n) e.clipboard:cut(n) end)
|
||||||
api.fs.paste = en(function(e, n) e.clipboard:paste(n) end)
|
api.fs.paste = en(function(e, n) e.clipboard:paste(n) end)
|
||||||
|
api.fs.move = en(function(e, n) e.clipboard:paste(n, { cut = true }) end)
|
||||||
api.fs.print_clipboard = e_(function(e) e.clipboard:print_clipboard() end)
|
api.fs.print_clipboard = e_(function(e) e.clipboard:print_clipboard() end)
|
||||||
api.fs.remove = _v(function(n) require("nvim-tree.actions.fs.remove-file").fn(n) end)
|
api.fs.remove = _v(function(n) require("nvim-tree.actions.fs.remove-file").fn(n) end)
|
||||||
api.fs.rename = _n(function(n) require("nvim-tree.actions.fs.rename-file").rename_node(n) end)
|
api.fs.rename = _n(function(n) require("nvim-tree.actions.fs.rename-file").rename_node(n) end)
|
||||||
@@ -182,10 +188,10 @@ function M.hydrate_post_setup(api)
|
|||||||
api.marks.navigate.select = e_(function(e) e.marks:navigate_select() end)
|
api.marks.navigate.select = e_(function(e) e.marks:navigate_select() end)
|
||||||
api.marks.toggle = ev(function(e, n) e.marks:toggle(n) end)
|
api.marks.toggle = ev(function(e, n) e.marks:toggle(n) end)
|
||||||
|
|
||||||
api.node.buffer.delete = _n(function(n, opts) require("nvim-tree.actions.node.buffer").delete(n, opts) end)
|
api.node.buffer.delete = _n(function(n, o) require("nvim-tree.actions.node.buffer").delete(n, o) end)
|
||||||
api.node.buffer.wipe = _n(function(n, opts) require("nvim-tree.actions.node.buffer").wipe(n, opts) end)
|
api.node.buffer.wipe = _n(function(n, o) require("nvim-tree.actions.node.buffer").wipe(n, o) end)
|
||||||
api.node.collapse = _n(function(n, opts) require("nvim-tree.actions.tree.collapse").node(n, opts) end)
|
api.node.collapse = _n(function(n, o) require("nvim-tree.actions.tree.collapse").node(n, o) end)
|
||||||
api.node.expand = en(function(e, n, opts) e:expand_node(n, opts) end)
|
api.node.expand = en(function(e, n, o) e:expand_node(n, o) end)
|
||||||
api.node.navigate.diagnostics.next = __(function() require("nvim-tree.actions.moves.item").diagnostics_next() end)
|
api.node.navigate.diagnostics.next = __(function() require("nvim-tree.actions.moves.item").diagnostics_next() end)
|
||||||
api.node.navigate.diagnostics.next_recursive = __(function() require("nvim-tree.actions.moves.item").diagnostics_next_recursive() end)
|
api.node.navigate.diagnostics.next_recursive = __(function() require("nvim-tree.actions.moves.item").diagnostics_next_recursive() end)
|
||||||
api.node.navigate.diagnostics.prev = __(function() require("nvim-tree.actions.moves.item").diagnostics_prev() end)
|
api.node.navigate.diagnostics.prev = __(function() require("nvim-tree.actions.moves.item").diagnostics_prev() end)
|
||||||
@@ -205,18 +211,21 @@ function M.hydrate_post_setup(api)
|
|||||||
api.node.navigate.sibling.next = _n(function(n) require("nvim-tree.actions.moves.sibling").next(n) end)
|
api.node.navigate.sibling.next = _n(function(n) require("nvim-tree.actions.moves.sibling").next(n) end)
|
||||||
api.node.navigate.sibling.prev = _n(function(n) require("nvim-tree.actions.moves.sibling").prev(n) end)
|
api.node.navigate.sibling.prev = _n(function(n) require("nvim-tree.actions.moves.sibling").prev(n) end)
|
||||||
api.node.open.drop = _n(function(n) require("nvim-tree.actions.node.open-file").drop(n) end)
|
api.node.open.drop = _n(function(n) require("nvim-tree.actions.node.open-file").drop(n) end)
|
||||||
api.node.open.edit = _n(function(n) require("nvim-tree.actions.node.open-file").edit(n) end)
|
api.node.open.edit = _n(function(n, o) require("nvim-tree.actions.node.open-file").edit(n, o) end)
|
||||||
api.node.open.horizontal = _n(function(n) require("nvim-tree.actions.node.open-file").horizontal(n) end)
|
api.node.open.horizontal = _n(function(n, o) require("nvim-tree.actions.node.open-file").horizontal(n, o) end)
|
||||||
api.node.open.horizontal_no_picker = _n(function(n) require("nvim-tree.actions.node.open-file").horizontal_no_picker(n) end)
|
api.node.open.horizontal_no_picker = _n(function(n, o)
|
||||||
api.node.open.no_window_picker = _n(function(n) require("nvim-tree.actions.node.open-file").no_window_picker(n) end)
|
require("nvim-tree.actions.node.open-file").horizontal_no_picker(n,
|
||||||
api.node.open.preview = _n(function(n) require("nvim-tree.actions.node.open-file").preview(n) end)
|
o)
|
||||||
api.node.open.preview_no_picker = _n(function(n) require("nvim-tree.actions.node.open-file").preview_no_picker(n) end)
|
end)
|
||||||
|
api.node.open.no_window_picker = _n(function(n, o) require("nvim-tree.actions.node.open-file").no_window_picker(n, o) end)
|
||||||
|
api.node.open.preview = _n(function(n, o) require("nvim-tree.actions.node.open-file").preview(n, o) end)
|
||||||
|
api.node.open.preview_no_picker = _n(function(n, o) require("nvim-tree.actions.node.open-file").preview_no_picker(n, o) end)
|
||||||
api.node.open.replace_tree_buffer = _n(function(n) require("nvim-tree.actions.node.open-file").replace_tree_buffer(n) end)
|
api.node.open.replace_tree_buffer = _n(function(n) require("nvim-tree.actions.node.open-file").replace_tree_buffer(n) end)
|
||||||
api.node.open.tab = _n(function(n) require("nvim-tree.actions.node.open-file").tab(n) end)
|
api.node.open.tab = _n(function(n, o) require("nvim-tree.actions.node.open-file").tab(n, o) end)
|
||||||
api.node.open.tab_drop = _n(function(n) require("nvim-tree.actions.node.open-file").tab_drop(n) end)
|
api.node.open.tab_drop = _n(function(n) require("nvim-tree.actions.node.open-file").tab_drop(n) end)
|
||||||
api.node.open.toggle_group_empty = _n(function(n) require("nvim-tree.actions.node.open-file").toggle_group_empty(n) end)
|
api.node.open.toggle_group_empty = _n(function(n) require("nvim-tree.actions.node.open-file").toggle_group_empty(n) end)
|
||||||
api.node.open.vertical = _n(function(n) require("nvim-tree.actions.node.open-file").vertical(n) end)
|
api.node.open.vertical = _n(function(n, o) require("nvim-tree.actions.node.open-file").vertical(n, o) end)
|
||||||
api.node.open.vertical_no_picker = _n(function(n) require("nvim-tree.actions.node.open-file").vertical_no_picker(n) end)
|
api.node.open.vertical_no_picker = _n(function(n, o) require("nvim-tree.actions.node.open-file").vertical_no_picker(n, o) end)
|
||||||
api.node.run.cmd = _n(function(n) require("nvim-tree.actions.node.run-command").run_file_command(n) end)
|
api.node.run.cmd = _n(function(n) require("nvim-tree.actions.node.run-command").run_file_command(n) end)
|
||||||
api.node.run.system = _n(function(n) require("nvim-tree.actions.node.system-open").fn(n) end)
|
api.node.run.system = _n(function(n) require("nvim-tree.actions.node.system-open").fn(n) end)
|
||||||
api.node.show_info_popup = _n(function(n) require("nvim-tree.actions.node.file-popup").toggle_file_info(n) end)
|
api.node.show_info_popup = _n(function(n) require("nvim-tree.actions.node.file-popup").toggle_file_info(n) end)
|
||||||
@@ -227,22 +236,22 @@ function M.hydrate_post_setup(api)
|
|||||||
api.tree.close = __(function() require("nvim-tree.view").close() end)
|
api.tree.close = __(function() require("nvim-tree.view").close() end)
|
||||||
api.tree.close_in_all_tabs = __(function() require("nvim-tree.view").close_all_tabs() end)
|
api.tree.close_in_all_tabs = __(function() require("nvim-tree.view").close_all_tabs() end)
|
||||||
api.tree.close_in_this_tab = __(function() require("nvim-tree.view").close_this_tab_only() end)
|
api.tree.close_in_this_tab = __(function() require("nvim-tree.view").close_this_tab_only() end)
|
||||||
api.tree.collapse_all = __(function(opts) require("nvim-tree.actions.tree.collapse").all(opts) end)
|
api.tree.collapse_all = __(function(o) require("nvim-tree.actions.tree.collapse").all(o) end)
|
||||||
api.tree.expand_all = en(function(e, n, opts) e:expand_all(n, opts) end)
|
api.tree.expand_all = en(function(e, n, o) e:expand_all(n, o) end)
|
||||||
api.tree.find_file = __(function(opts) require("nvim-tree.actions.tree.find-file").fn(opts) end)
|
api.tree.find_file = __(function(o) require("nvim-tree.actions.tree.find-file").fn(o) end)
|
||||||
api.tree.focus = __(function(opts) require("nvim-tree.actions.tree.open").fn(opts) end)
|
api.tree.focus = __(function(o) require("nvim-tree.actions.tree.open").fn(o) end)
|
||||||
api.tree.get_node_under_cursor = en(function(e) return e:get_node_at_cursor() end)
|
api.tree.get_node_under_cursor = en(function(e) return e:get_node_at_cursor() end)
|
||||||
api.tree.get_nodes = en(function(e) return e:get_nodes() end)
|
api.tree.get_nodes = en(function(e) return e:get_nodes() end)
|
||||||
api.tree.is_tree_buf = __(function(bufnr) return require("nvim-tree.utils").is_nvim_tree_buf(bufnr) end)
|
api.tree.is_tree_buf = __(function(bufnr) return require("nvim-tree.utils").is_nvim_tree_buf(bufnr) end)
|
||||||
api.tree.is_visible = __(function(opts) return require("nvim-tree.view").is_visible(opts) end)
|
api.tree.is_visible = __(function(o) return require("nvim-tree.view").is_visible(o) end)
|
||||||
api.tree.open = __(function(opts) require("nvim-tree.actions.tree.open").fn(opts) end)
|
api.tree.open = __(function(o) require("nvim-tree.actions.tree.open").fn(o) end)
|
||||||
api.tree.reload = e_(function(e) e:reload_explorer() end)
|
api.tree.reload = e_(function(e) e:reload_explorer() end)
|
||||||
api.tree.reload_git = e_(function(e) e:reload_git() end)
|
api.tree.reload_git = e_(function(e) e:reload_git() end)
|
||||||
api.tree.resize = __(function(opts) require("nvim-tree.actions.tree.resize").fn(opts) end)
|
api.tree.resize = __(function(o) require("nvim-tree.actions.tree.resize").fn(o) end)
|
||||||
api.tree.search_node = __(function() require("nvim-tree.actions.finders.search-node").fn() end)
|
api.tree.search_node = __(function() require("nvim-tree.actions.finders.search-node").fn() end)
|
||||||
api.tree.toggle = __(function(opts) require("nvim-tree.actions.tree.toggle").fn(opts) end)
|
api.tree.toggle = __(function(o) require("nvim-tree.actions.tree.toggle").fn(o) end)
|
||||||
api.tree.toggle_help = __(function() require("nvim-tree.help").toggle() end)
|
api.tree.toggle_help = __(function() require("nvim-tree.help").toggle() end)
|
||||||
api.tree.winid = __(function(opts) return require("nvim-tree.view").winid(opts) end)
|
api.tree.winid = __(function(o) return require("nvim-tree.view").winid(o) end)
|
||||||
|
|
||||||
-- Map all legacy functions to implementations
|
-- Map all legacy functions to implementations
|
||||||
require("nvim-tree.legacy").map_api(api)
|
require("nvim-tree.legacy").map_api(api)
|
||||||
|
|||||||
@@ -17,6 +17,28 @@ function M.global()
|
|||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if vim.fn.has("nvim-0.13") == 1 and config.g.experimental.session_restore_nvim then
|
||||||
|
vim.api.nvim_create_autocmd("SessionWritePre", { ---@diagnostic disable-line: param-type-mismatch
|
||||||
|
group = augroup_id,
|
||||||
|
callback = function()
|
||||||
|
-- We must schedule to wait until `vim.v.this_session` is properly updated
|
||||||
|
-- This prevents overwriting the data if a new session is created with a new `:mksession`
|
||||||
|
vim.schedule(require("nvim-tree.session").save)
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
vim.api.nvim_create_autocmd("SessionLoadPost", {
|
||||||
|
group = augroup_id,
|
||||||
|
-- Workaround: this event fires multiple times (report upstream),
|
||||||
|
-- failure notifications could show up many times.
|
||||||
|
once = true,
|
||||||
|
callback = function()
|
||||||
|
require("nvim-tree.session").restore()
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
if config.g.tab.sync.open then
|
if config.g.tab.sync.open then
|
||||||
vim.api.nvim_create_autocmd("TabEnter", {
|
vim.api.nvim_create_autocmd("TabEnter", {
|
||||||
group = augroup_id,
|
group = augroup_id,
|
||||||
|
|||||||
@@ -297,6 +297,7 @@ M.d = { -- config-default-start
|
|||||||
persist = false,
|
persist = false,
|
||||||
},
|
},
|
||||||
experimental = {
|
experimental = {
|
||||||
|
session_restore_nvim = false
|
||||||
},
|
},
|
||||||
log = {
|
log = {
|
||||||
enable = false,
|
enable = false,
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ function M.on_attach_default(bufnr)
|
|||||||
vim.keymap.set("n", "F", api.filter.live.clear, opts("Live Filter: Clear"))
|
vim.keymap.set("n", "F", api.filter.live.clear, opts("Live Filter: Clear"))
|
||||||
vim.keymap.set("n", "f", api.filter.live.start, opts("Live Filter: Start"))
|
vim.keymap.set("n", "f", api.filter.live.start, opts("Live Filter: Start"))
|
||||||
vim.keymap.set("n", "g?", api.tree.toggle_help, opts("Help"))
|
vim.keymap.set("n", "g?", api.tree.toggle_help, opts("Help"))
|
||||||
vim.keymap.set("n", "gy", api.fs.copy.absolute_path, opts("Copy Absolute Path"))
|
vim.keymap.set({ "n", "x" }, "gy", api.fs.copy.absolute_path, opts("Copy Absolute Path"))
|
||||||
vim.keymap.set("n", "ge", api.fs.copy.basename, opts("Copy Basename"))
|
vim.keymap.set("n", "ge", api.fs.copy.basename, opts("Copy Basename"))
|
||||||
vim.keymap.set("n", "H", api.filter.dotfiles.toggle, opts("Toggle Filter: Dotfiles"))
|
vim.keymap.set("n", "H", api.filter.dotfiles.toggle, opts("Toggle Filter: Dotfiles"))
|
||||||
vim.keymap.set("n", "I", api.filter.git.ignored.toggle, opts("Toggle Filter: Git Ignored"))
|
vim.keymap.set("n", "I", api.filter.git.ignored.toggle, opts("Toggle Filter: Git Ignored"))
|
||||||
@@ -102,6 +102,7 @@ function M.on_attach_default(bufnr)
|
|||||||
vim.keymap.set("n", "o", api.node.open.edit, opts("Open"))
|
vim.keymap.set("n", "o", api.node.open.edit, opts("Open"))
|
||||||
vim.keymap.set("n", "O", api.node.open.no_window_picker, opts("Open: No Window Picker"))
|
vim.keymap.set("n", "O", api.node.open.no_window_picker, opts("Open: No Window Picker"))
|
||||||
vim.keymap.set("n", "p", api.fs.paste, opts("Paste"))
|
vim.keymap.set("n", "p", api.fs.paste, opts("Paste"))
|
||||||
|
vim.keymap.set("n", "gp", api.fs.move, opts("Move"))
|
||||||
vim.keymap.set("n", "P", api.node.navigate.parent, opts("Parent Directory"))
|
vim.keymap.set("n", "P", api.node.navigate.parent, opts("Parent Directory"))
|
||||||
vim.keymap.set("n", "q", api.tree.close, opts("Close"))
|
vim.keymap.set("n", "q", api.tree.close, opts("Close"))
|
||||||
vim.keymap.set("n", "r", api.fs.rename, opts("Rename"))
|
vim.keymap.set("n", "r", api.fs.rename, opts("Rename"))
|
||||||
|
|||||||
103
lua/nvim-tree/session.lua
Normal file
103
lua/nvim-tree/session.lua
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
local notify = require("nvim-tree.notify")
|
||||||
|
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
local storepath = vim.fn.stdpath("data") .. "/nvim-tree-session.json"
|
||||||
|
|
||||||
|
local function decode_session_file()
|
||||||
|
local file = io.open(storepath, "r")
|
||||||
|
|
||||||
|
if file then
|
||||||
|
local content = file:read("*all")
|
||||||
|
file:close()
|
||||||
|
if content and content ~= "" then
|
||||||
|
return vim.json.decode(content)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- Notifying on failure could be noisy, as it'd happen if the file simply did not exist
|
||||||
|
end
|
||||||
|
|
||||||
|
local function write_session_file(session_file_content)
|
||||||
|
local file, errmsg = io.open(storepath, "w")
|
||||||
|
|
||||||
|
if file then
|
||||||
|
file:write(vim.json.encode(session_file_content))
|
||||||
|
file:close()
|
||||||
|
else
|
||||||
|
notify.warn(string.format("Invalid session file (%s): %s", storepath, errmsg))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.save()
|
||||||
|
-- We either always save the session data, which ends up populating the storepath with empty data
|
||||||
|
-- Or we gate by the tree's visibility, which could create "out of sync" scenario:
|
||||||
|
-- if the tree is initially open and the session is saved, it won't be overridden later,
|
||||||
|
-- if the tree is no longer visible. However, when restoring, this is harmless.
|
||||||
|
if require("nvim-tree.api").tree.is_visible({ any_tabpage = true }) then
|
||||||
|
local ok, session_file_content = pcall(decode_session_file)
|
||||||
|
|
||||||
|
if not ok then
|
||||||
|
notify.warn(string.format("Failed to decode session file (%s): %s", storepath, session_file_content))
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- might be nil at this point
|
||||||
|
session_file_content = session_file_content or {}
|
||||||
|
|
||||||
|
local cwd = require("nvim-tree.core").get_cwd()
|
||||||
|
|
||||||
|
session_file_content[vim.v.this_session] = { cwd = cwd }
|
||||||
|
|
||||||
|
local ok2, err = pcall(write_session_file, session_file_content)
|
||||||
|
|
||||||
|
if not ok2 then
|
||||||
|
notify.warn(string.format("Failed to write session file (%s): %s", storepath, err))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.restore()
|
||||||
|
local api = require("nvim-tree.api").tree
|
||||||
|
|
||||||
|
---@type table<integer,boolean>
|
||||||
|
local tabs = {}
|
||||||
|
|
||||||
|
local ok, session_file_content = pcall(decode_session_file)
|
||||||
|
|
||||||
|
-- Failing to restore cwd is not fatal, we can continue
|
||||||
|
if not ok then
|
||||||
|
notify.warn(string.format("Failed to decode session file (%s): %s", storepath, session_file_content))
|
||||||
|
end
|
||||||
|
|
||||||
|
local path = session_file_content and session_file_content[vim.v.this_session] and session_file_content[vim.v.this_session].cwd or nil
|
||||||
|
|
||||||
|
-- Save tabs with leftover nvim-tree buffers
|
||||||
|
for _, tab in ipairs(vim.api.nvim_list_tabpages()) do
|
||||||
|
for _, win in ipairs(vim.api.nvim_tabpage_list_wins(tab)) do
|
||||||
|
local buf = vim.api.nvim_win_get_buf(win)
|
||||||
|
if api.is_tree_buf(buf) then
|
||||||
|
tabs[tab] = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- The new window may inherit options from the current one if we don't schedule
|
||||||
|
vim.schedule(function()
|
||||||
|
api.close_in_all_tabs()
|
||||||
|
|
||||||
|
for tab, _ in pairs(tabs) do
|
||||||
|
if vim.api.nvim_tabpage_is_valid(tab) then
|
||||||
|
local win = vim.api.nvim_tabpage_get_win(tab)
|
||||||
|
|
||||||
|
-- Invoke `open` from each tab's current window to prevent having to switch tabs
|
||||||
|
if vim.api.nvim_win_is_valid(win) then
|
||||||
|
vim.api.nvim_win_call(win, function()
|
||||||
|
api.open({ path = path })
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
||||||
@@ -71,7 +71,7 @@ end
|
|||||||
|
|
||||||
---Configure width-related config
|
---Configure width-related config
|
||||||
---@param width string|function|number|table|nil
|
---@param width string|function|number|table|nil
|
||||||
local function configure_width(width)
|
function M.configure_width(width)
|
||||||
if type(width) == "table" then
|
if type(width) == "table" then
|
||||||
M.Active.adaptive_size = true
|
M.Active.adaptive_size = true
|
||||||
M.Active.width = width.min or DEFAULT_MIN_WIDTH
|
M.Active.width = width.min or DEFAULT_MIN_WIDTH
|
||||||
@@ -101,7 +101,7 @@ function M.initialize()
|
|||||||
M.Active.winopts.relativenumber = config.g.view.relativenumber
|
M.Active.winopts.relativenumber = config.g.view.relativenumber
|
||||||
M.Active.winopts.signcolumn = config.g.view.signcolumn
|
M.Active.winopts.signcolumn = config.g.view.signcolumn
|
||||||
|
|
||||||
configure_width(config.g.view.width)
|
M.configure_width(config.g.view.width)
|
||||||
|
|
||||||
M.Active.initial_width = M.get_width()
|
M.Active.initial_width = M.get_width()
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -298,7 +298,7 @@ function M.resize(size)
|
|||||||
local new_size = view_state.get_width()
|
local new_size = view_state.get_width()
|
||||||
|
|
||||||
if new_size ~= vim.api.nvim_win_get_width(winnr) then
|
if new_size ~= vim.api.nvim_win_get_width(winnr) then
|
||||||
vim.api.nvim_win_set_width(winnr, new_size)
|
vim.api.nvim_win_set_width(winnr, new_size) ---@diagnostic disable-line: deprecated see #3344
|
||||||
if not config.g.view.preserve_window_proportions then
|
if not config.g.view.preserve_window_proportions then
|
||||||
vim.cmd(":wincmd =")
|
vim.cmd(":wincmd =")
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user