Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implemented changes intially created by @daog1 and addresses the comm… #1016

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions lua/neo-tree/defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,8 @@ local config = {
["p"] = "paste_from_clipboard",
["c"] = "copy", -- takes text input for destination, also accepts the config.show_path and config.insert_as options
["m"] = "move", -- takes text input for destination, also accepts the config.show_path and config.insert_as options
["Y"] = "copy_path",
["gy"] = "copy_abspath",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only problem here is that the commands are defined at the global level so that it applies to all sources, but it is not really a command that will work universally. It should be mapped within the filesystem and buffers commands instead.

It also makes sense to use it in the git_status source.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is correct. For example, Netman explodes when you navigate to it's Neo-tree source because I don't have these commands implemented yet. IMO they should not be "common".
Or if they are, this release needs to be slow walked as this should be considered a "Breaking Change" for 3rd party developers using Neo-tree.

That said, I really like this feature, so whatever command is decided on, I will implement it in Netman. But the fact that this causes an error on source load means this is IMO a breaking change.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgive my ignorance, and would you explain it in more detail,thx alot

["e"] = "toggle_auto_expand_width",
["q"] = "close_window",
["?"] = "show_help",
Expand Down
8 changes: 8 additions & 0 deletions lua/neo-tree/sources/buffers/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ M.copy = function(state)
cc.copy(state, redraw)
end

M.copy_path = function(state)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is needed at all because there is a

cc._add_common_commands(M)

call at the end of the file, which will add this command anyhow. This pattern of wrapping common commands is only needed when we need to alter the common command in some way, such as by adding a redraw callback.

cc.copy_path(state)
end

M.copy_abspath = function(state)
cc.copy_abspath(state)
end

M.move = function(state)
cc.move(state, redraw)
end
Expand Down
28 changes: 28 additions & 0 deletions lua/neo-tree/sources/common/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,34 @@ M.copy = function(state, callback)
fs_actions.copy_node(node.path, nil, callback, using_root_directory)
end

---Copies a node relative path to clipboard.
---@param state table The state of the source
M.copy_path = function(state)
local node = state.tree:get_node()
if node.type == "message" then
return
end
local pwdpath = state.path
local content = node.path
Comment on lines +491 to +492
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a common command, there's no guarantee that either of these exist for all sources.

Suggested change
local pwdpath = state.path
local content = node.path
local pwdpath = state.path or ""
local content = node.path or node:get_id()

local rpath = "." .. string.sub(content, string.len(pwdpath) + 1)
vim.fn.setreg("+", rpath)
vim.fn.setreg('"', rpath)
log.info("copy " .. node.name .. " path to clipboard")
end

---Copies a node absolute path to clipboard.
---@param state table The state of the source
M.copy_abspath = function(state)
local node = state.tree:get_node()
if node.type == "message" then
return
end
local content = node.path
vim.fn.setreg("+", content)
vim.fn.setreg('"', content)
log.info("copy " .. node.name .. "abs path to clipboard")
end

---Moves a node to a new location, using typed input.
---@param state table The state of the source
---@param callback function The callback to call when the command is done. Called with the parent node as the argument.
Expand Down
8 changes: 8 additions & 0 deletions lua/neo-tree/sources/filesystem/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ M.copy = function(state)
cc.copy(state, utils.wrap(refresh, state))
end

M.copy_path = function(state)
cc.copy_path(state)
end

M.copy_abspath = function(state)
cc.copy_abspath(state)
end

Comment on lines +35 to +42
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These can be deleted as well.

---Marks node as copied, so that it can be pasted somewhere else.
M.copy_to_clipboard = function(state)
cc.copy_to_clipboard(state, utils.wrap(redraw, state))
Expand Down