-
-
Notifications
You must be signed in to change notification settings - Fork 624
fix: file creation in empty folder without root_folder_label #2514
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
fix: file creation in empty folder without root_folder_label #2514
Conversation
4fd81e2
to
7bc7043
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contribution:
Tested OK except there is an issue:
root_folder_label = ":~:s?$?/..?"
- add multiple files
- add multiple folders
- add mix
root_folder_label = false
- add multiple files
- add multiple folders
- add mix
issue:
on empty root node navigates up a directory
lua/nvim-tree/lib.lua
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure we can make this fix here: get_node_at_cursor
is used in a great many places and there are assumptions that it will return nil if the tree is empty and root folder hidden.
Could we make this change specifically in the add function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main problem in this function which used for all api functions:
local function wrap_node(f)
return function(node, ...)
node = node or require("nvim-tree.lib").get_node_at_cursor()
if node then
f(node, ...)
end
end
end
get_node_at_cursor
returns nil
and stops execution. in add
function handle already exists
function M.fn(node)
node = node and lib.get_last_group_node(node)
if not node or node.name == ".." then
node = {
absolute_path = core.get_cwd(),
nodes = core.get_explorer().nodes,
open = true,
}
end
There are few options we can do:
- Make another wrapper without
if node then
; - Add second param to
wrap_node
which would be true by default, kind ofskip_if_nil
, we can add to other api calls if needed to skip or not and it would be look like this:
local function wrap_node(f, skip_if_nil_node)
return function(node, ...)
node = node or require("nvim-tree.lib").get_node_at_cursor()
if skip_if_nil_node or node then
f(node, ...)
end
end
end
@alex-courtis Could you please describe |
7db3638
to
aab108a
Compare
@alex-courtis So what do you think about current solution? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pragmatic and safe.
API is a bit of a mess and adding boolean arguments isn't the best for readability.
Could you please add a specific method, maybe wrap_node_or_nil
@@ -41,12 +41,13 @@ local function wrap(f) | |||
end | |||
|
|||
--- Inject the node as the first argument if absent. | |||
--- f function to invoke | |||
local function wrap_node(f) | |||
---@param fn function function to invoke |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you.
aab108a
to
25aa1e9
Compare
25aa1e9
to
c406b92
Compare
c406b92
to
816dffd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fantastic work, thank you!
Fixes: #2512