Skip to content

feat(view): Floating nvim tree window #1377 #1462

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 13 commits into from
Aug 6, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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
8 changes: 8 additions & 0 deletions doc/nvim-tree-lua.txt
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,14 @@ Subsequent calls to setup will replace the previous configuration.
-- user mappings go here
},
},
float = {
enable = false,
-- options passed to nvim_open_win()
relative = "editor",
row = 1,
col = 1,
border = "rounded",
Copy link
Member

Choose a reason for hiding this comment

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

should be documented. specially because:

Requires setting nvim-tree.actions.open_file.quit_on_open to true to work properly.

Copy link
Member

Choose a reason for hiding this comment

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

If we require this, quit_on_open should be overridden and set when float.enable is set.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

quit_on_open is now enforced if float.enable is set.

},
},
renderer = {
add_trailing = false,
Expand Down
8 changes: 8 additions & 0 deletions lua/nvim-tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,14 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
-- user mappings go here
},
},
float = {
enable = false,
-- options passed to nvim_open_win()
relative = "editor",
row = 1,
col = 1,
border = "rounded",
},
},
renderer = {
add_trailing = false,
Expand Down
20 changes: 18 additions & 2 deletions lua/nvim-tree/view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ M.View = {
"NormalNC:NvimTreeNormalNC",
}, ","),
},
floatenable = false,
floatopts = {
relative = "editor",
row = 1,
col = 1,
border = "rounded",
},
}

-- The initial state of a tab
Expand Down Expand Up @@ -129,8 +136,12 @@ local function set_window_options_and_buffer()
end

local function open_window()
a.nvim_command "vsp"
M.reposition_window()
if M.View.floatenable then
a.nvim_open_win(0, true, M.View.floatopts)
else
a.nvim_command "vsp"
M.reposition_window()
end
setup_tabpage(a.nvim_get_current_tabpage())
set_window_options_and_buffer()
end
Expand Down Expand Up @@ -426,6 +437,11 @@ function M.setup(opts)
M.View.winopts.number = options.number
M.View.winopts.relativenumber = options.relativenumber
M.View.winopts.signcolumn = options.signcolumn
M.View.floatenable = options.float.enable
M.View.floatopts = options.float
M.View.floatopts.width = options.width
M.View.floatopts.height = options.height
M.View.floatopts.enable = nil
end

return M