Skip to content

fix: api.node.open.preview should toggle directories #2099

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

Merged
merged 1 commit into from
Apr 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lua/nvim-tree/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,13 @@ local function open_or_expand_or_dir_up(mode)
end

local function open_preview(node)
if node.nodes or node.name == ".." then
return
if node.name == ".." then
require("nvim-tree.actions.root.change-dir").fn ".."
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Might want to return early here. This was inline with previous behaviour.

Suggested change
require("nvim-tree.actions.root.change-dir").fn ".."
return

Copy link
Member

Choose a reason for hiding this comment

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

Testing with 9c97e64 (before on_attach): preview does nothing on the root directory.

However, the change-dir does make sense and brings it in line with open.

How about this help:

api.node.open.edit()                          *nvim-tree.api.node.open.edit()*
    File:   open as per |nvim-tree.actions.open_file|
    Folder: expand or collapse
    Root:   change directory up

api.node.open.preview()                    *nvim-tree.api.node.open.preview()*
    Perform |nvim-tree.api.node.edit()|
    File buffer will have |bufhidden| set to `delete`.

elseif node.nodes then
require("nvim-tree.lib").expand_or_collapse(node)
else
edit("preview", node)
end

edit("preview", node)
end

Api.node.open.edit = inject_node(open_or_expand_or_dir_up "edit")
Expand Down