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 8 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: 10 additions & 0 deletions doc/nvim-tree-lua.txt
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,16 @@ Subsequent calls to setup will replace the previous configuration.
-- user mappings go here
},
},
float = {
-- enabling enforces `actions.open_file.quit_on_open`
enable = false,
-- options passed to nvim_open_win()
relative = "editor",
row = 1,
col = 1,
anchor = "NW",
border = "rounded",
},
},
renderer = {
add_trailing = false,
Expand Down
10 changes: 10 additions & 0 deletions lua/nvim-tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,16 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
-- user mappings go here
},
},
float = {
-- enabling enforces `actions.open_file.quit_on_open`
enable = false,
-- options passed to nvim_open_win()
relative = "editor",
row = 1,
col = 1,
anchor = "NW",
border = "rounded",
},
},
renderer = {
add_trailing = false,
Expand Down
2 changes: 1 addition & 1 deletion lua/nvim-tree/actions/node/open-file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ function M.fn(mode, filename)
end

function M.setup(opts)
M.quit_on_open = opts.actions.open_file.quit_on_open
M.quit_on_open = opts.actions.open_file.quit_on_open or opts.view.float.enable
M.resize_window = opts.actions.open_file.resize_window
if opts.actions.open_file.window_picker.chars then
opts.actions.open_file.window_picker.chars = tostring(opts.actions.open_file.window_picker.chars):upper()
Expand Down
21 changes: 19 additions & 2 deletions lua/nvim-tree/view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ M.View = {
"NormalNC:NvimTreeNormalNC",
}, ","),
},
floatenable = false,
floatopts = {
relative = "editor",
row = 1,
col = 1,
anchor = "NW",
border = "rounded",
},
}

-- The initial state of a tab
Expand Down Expand Up @@ -134,8 +142,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 @@ -431,6 +443,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
M.on_attach = opts.on_attach
end

Expand Down