Skip to content

Conversation

@geril07
Copy link
Collaborator

@geril07 geril07 commented Nov 6, 2023

Fixes: #2512

@geril07 geril07 force-pushed the fix/empty-folder-without-root-label branch from 4fd81e2 to 7bc7043 Compare November 6, 2023 22:13
Copy link
Member

@alex-courtis alex-courtis left a 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

Copy link
Member

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?

Copy link
Collaborator Author

@geril07 geril07 Nov 6, 2023

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:

  1. Make another wrapper without if node then;
  2. Add second param to wrap_node which would be true by default, kind of skip_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

@geril07
Copy link
Collaborator Author

geril07 commented Nov 6, 2023

@alex-courtis Could you please describe on empty root node navigates up a directory. I guess i have no trouble with it.

@geril07 geril07 force-pushed the fix/empty-folder-without-root-label branch 2 times, most recently from 7db3638 to aab108a Compare November 7, 2023 00:18
@geril07 geril07 requested a review from alex-courtis November 7, 2023 00:21
@geril07
Copy link
Collaborator Author

geril07 commented Nov 7, 2023

@alex-courtis So what do you think about current solution?

Copy link
Member

@alex-courtis alex-courtis left a 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

--- Inject the node as the first argument if absent.
--- f function to invoke
local function wrap_node(f)
---@param fn function function to invoke
Copy link
Member

Choose a reason for hiding this comment

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

Thank you.

@geril07 geril07 force-pushed the fix/empty-folder-without-root-label branch from aab108a to 25aa1e9 Compare November 7, 2023 06:46
@geril07 geril07 requested a review from alex-courtis November 7, 2023 06:47
@geril07 geril07 force-pushed the fix/empty-folder-without-root-label branch from 25aa1e9 to c406b92 Compare November 7, 2023 13:16
@geril07 geril07 force-pushed the fix/empty-folder-without-root-label branch from c406b92 to 816dffd Compare November 7, 2023 13:17
Copy link
Member

@alex-courtis alex-courtis left a 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!

@alex-courtis alex-courtis merged commit 4ee6366 into nvim-tree:master Nov 7, 2023
@geril07 geril07 deleted the fix/empty-folder-without-root-label branch November 8, 2023 06:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot create file in empty directory without root label

2 participants