-
-
Notifications
You must be signed in to change notification settings - Fork 611
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(view): allow function for view.float.open_win_config #1538
Conversation
|
Thanks! Tested and it works! Something that caught me off-guard is that I also need to define This is what I have, for reference:
|
Interesting. Do view.width/height override If that's the case we should probably ignore view.width/height when floating. That will require deeper digging, as there are some other cases to consider, such as adaptive_width. |
Testing more, the problem seems to be only with
Opens a float window with height=3 and width=30. Even if I remove This opens with height=100 and width=100:
|
Thank you. Raised #1543 with your workaround documented. |
Hi. I hope this is the right place to ask this question; please tell me otherwise. I used the code given in the comments to center my floating window. require('nvim-tree').setup({
hijack_cursor = true,
actions = {
open_file = {
quit_on_open = true,
window_picker = {
enable = true,
}
}
},
diagnostics = {
enable = true,
show_on_dirs = true
},
filters = {
dotfiles = true
},
renderer = {
full_name = true,
highlight_git = true,
indent_width = 4,
},
tab = {
sync = {
open = true
}
},
view = {
float = {
enable = true,
-- Center the window
-- Thanks https://github.com/nvim-tree/nvim-tree.lua/pull/1538
open_win_config = function()
local screen_w = vim.opt.columns:get()
local screen_h = vim.opt.lines:get() - vim.opt.cmdheight:get()
local _height = screen_h * 0.8
local _width = screen_w * 0.8
local width = math.floor(_width)
local height = math.floor(_height)
local center_y = ((vim.opt.lines:get() - _height) / 2)
- vim.opt.cmdheight:get()
local center_x = (screen_w - _width) / 2
return {
anchor = 'NW',
relative = 'editor',
border = 'single',
row = center_y,
col = center_x,
width = width,
height = height,
}
end,
},
width = function()
return math.floor(vim.opt.columns:get() * 0.7)
end,
height = function()
return math.floor((vim.opt.lines:get() - vim.opt.cmdheight:get()) * 0.5)
end,
adaptive_size = true,
mappings = {
custom_only = false,
list = {
{
key = "l",
action = "edit",
action_cb = edit_or_open },
{
key = "L",
action = "vsplit_preview",
action_cb = vsplit_preview },
{
key = "h",
action = "close_node" },
{
key = "H",
action = "collapse_all",
action_cb = collapse_all }
}
},
},
}) Unfortunately, borders lost their radius. How can I add the original radius? Or even better, is there or will be a more automatic, better way to center the floating window? Thanks a lot for this beautiful work. |
No worries, we can discuss here. We can open an issue later if we'r looking at making changes. That's quite a nice solution. Perhaps you might add it to the wiki Recipes for others to use.
Dumb question: are the borders losing their radius due to |
Sure, I'm happy to do it! I added a minor change to the code, deleting the I also deleted If those changes are right for you then I can write the recipe. The complete code is: local HEIGHT_RATIO = 0.8
local WIDTH_RATIO = 0.5
require('nvim-tree').setup({
view = {
float = {
enable = true,
open_win_config = function()
local screen_w = vim.opt.columns:get()
local screen_h = vim.opt.lines:get() - vim.opt.cmdheight:get()
local window_w = screen_w * WIDTH_RATIO
local window_h = screen_h * HEIGHT_RATIO
local window_w_int = math.floor(window_w)
local window_h_int = math.floor(window_h)
local center_x = (screen_w - window_w) / 2
local center_y = ((vim.opt.lines:get() - window_h) / 2)
- vim.opt.cmdheight:get()
return {
border = 'rounded',
relative = 'editor',
row = center_y,
col = center_x,
width = window_w_int,
height = window_h_int,
}
end,
},
width = function()
return math.floor(vim.opt.columns:get() * WIDTH_RATIO)
end,
},
})
Hey no need to call my question dumb, let's keep this place civil! :) Sorry btw |
I am pretty sure Alex meant his own question. |
Oh in that case I sincerely apologize for the misunderstanding. My bad. |
I'm actually a little confused about how the border became rounded at all as your config should have always applied single. It's working as expected now 🤷 |
(Just a quick message to mention that I did not forget about the recipe; as I am very busy, I will write it at the end of the week.) |
Of course. It's using vim default as the nvim-tree default table is completely removed. |
Hello all. My apologies if this is a silly question, I am still quite new to nvim. I have a question in regard to this floating window. If I pass a directory to neovim upon running it, I will get a nvim-tree, but it is not the floating one. If I hit my tree toggle command to hide it and then reopen it, it will show the floating one (demonstrated below). Is there something different I have to do, such as delaying the initial loading of the tree until after all of the settings have 'taken'? 2023-01-09.18-38-48.mp4 |
That's a bug. Startup is problematic and experiences many race conditions. A new mechanism is incoming: #1669 |
And thanks, this feature is great :) |
Please open new issue (or discussion, more likely, as recipes from wiki aren't really "official") rather then commenting on months old pr. |
resolves #1512