Skip to content

Commit 1ba18da

Browse files
committed
fix(#2917): fix root copy paths: Y, ge, gy, y
1 parent 03ae603 commit 1ba18da

File tree

2 files changed

+49
-9
lines changed

2 files changed

+49
-9
lines changed

Diff for: doc/nvim-tree-lua.txt

+8
Original file line numberDiff line numberDiff line change
@@ -1960,6 +1960,13 @@ fs.copy.absolute_path({node}) *nvim-tree-api.fs.copy.absolute_path()*
19601960
Parameters: ~
19611961
{node} (Node|nil) file or folder
19621962

1963+
fs.copy.basename({node}) *nvim-tree-api.fs.copy.basename()*
1964+
Copy the name of a file or folder with extension omitted to the system
1965+
clipboard.
1966+
1967+
Parameters: ~
1968+
{node} (Node|nil) file or folder
1969+
19631970
fs.copy.filename({node}) *nvim-tree-api.fs.copy.filename()*
19641971
Copy the name of a file or folder to the system clipboard.
19651972

@@ -3027,6 +3034,7 @@ highlight group is not, hard linking as follows: >
30273034
|nvim-tree-api.events.subscribe()|
30283035
|nvim-tree-api.fs.clear_clipboard()|
30293036
|nvim-tree-api.fs.copy.absolute_path()|
3037+
|nvim-tree-api.fs.copy.basename()|
30303038
|nvim-tree-api.fs.copy.filename()|
30313039
|nvim-tree-api.fs.copy.node()|
30323040
|nvim-tree-api.fs.copy.relative_path()|

Diff for: lua/nvim-tree/actions/fs/clipboard.lua

+41-9
Original file line numberDiff line numberDiff line change
@@ -327,30 +327,62 @@ end
327327

328328
---@param node Node
329329
function Clipboard:copy_filename(node)
330-
self:copy_to_reg(node.name)
330+
local content
331+
332+
if node.name == ".." then
333+
-- root
334+
content = vim.fn.fnamemodify(self.explorer.absolute_path, ":t")
335+
else
336+
-- node
337+
content = node.name
338+
end
339+
340+
self:copy_to_reg(content)
331341
end
332342

333343
---@param node Node
334344
function Clipboard:copy_basename(node)
335-
local basename = vim.fn.fnamemodify(node.name, ":r")
336-
self:copy_to_reg(basename)
345+
local content
346+
347+
if node.name == ".." then
348+
-- root
349+
content = vim.fn.fnamemodify(self.explorer.absolute_path, ":t:r")
350+
else
351+
-- node
352+
content = vim.fn.fnamemodify(node.name, ":r")
353+
end
354+
355+
self:copy_to_reg(content)
337356
end
338357

339358
---@param node Node
340359
function Clipboard:copy_path(node)
341-
local absolute_path = node.absolute_path
342-
local cwd = core.get_cwd()
343-
if cwd == nil then
344-
return
360+
local content
361+
362+
if node.name == ".." then
363+
-- root
364+
content = utils.path_add_trailing ""
365+
else
366+
-- node
367+
local absolute_path = node.absolute_path
368+
local cwd = core.get_cwd()
369+
if cwd == nil then
370+
return
371+
end
372+
373+
local relative_path = utils.path_relative(absolute_path, cwd)
374+
content = node.nodes ~= nil and utils.path_add_trailing(relative_path) or relative_path
345375
end
346376

347-
local relative_path = utils.path_relative(absolute_path, cwd)
348-
local content = node.nodes ~= nil and utils.path_add_trailing(relative_path) or relative_path
349377
self:copy_to_reg(content)
350378
end
351379

352380
---@param node Node
353381
function Clipboard:copy_absolute_path(node)
382+
if node.name == ".." then
383+
node = self.explorer
384+
end
385+
354386
local absolute_path = node.absolute_path
355387
local content = node.nodes ~= nil and utils.path_add_trailing(absolute_path) or absolute_path
356388
self:copy_to_reg(content)

0 commit comments

Comments
 (0)