-
-
Notifications
You must be signed in to change notification settings - Fork 57
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
feat: resize window on nvim resize #117
base: main
Are you sure you want to change the base?
Conversation
fix: resize event name fix: try fix resize fix: resize fix: resize fix: resie
Thank you for the PR! This is something I've been meaning to look into for a while but haven't had the time to get to it. |
vim.api.nvim_create_autocmd('VimResized', { | ||
callback = function() | ||
vim.defer_fn(function() | ||
if not vim.api.nvim_win_is_valid(border_window) then | ||
return | ||
end | ||
local new_width, new_height, new_row, new_col = get_window_pos() | ||
api.nvim_win_set_config(border_window, | ||
{ width = new_width + 2, height = new_height + 2, relative = 'editor', row = new_row - 1, col = new_col - 1, }) | ||
api.nvim_win_set_config(win, | ||
{ width = new_width, height = new_height, relative = 'editor', row = new_row, col = new_col, }) | ||
end, 20) | ||
end | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you elaborate on why defer_fn
is needed?
Would this not work?
vim.api.nvim_create_autocmd('VimResized', { | |
callback = function() | |
vim.defer_fn(function() | |
if not vim.api.nvim_win_is_valid(border_window) then | |
return | |
end | |
local new_width, new_height, new_row, new_col = get_window_pos() | |
api.nvim_win_set_config(border_window, | |
{ width = new_width + 2, height = new_height + 2, relative = 'editor', row = new_row - 1, col = new_col - 1, }) | |
api.nvim_win_set_config(win, | |
{ width = new_width, height = new_height, relative = 'editor', row = new_row, col = new_col, }) | |
end, 20) | |
end | |
}) | |
vim.api.nvim_create_autocmd('VimResized', { | |
callback = function() | |
if not vim.api.nvim_win_is_valid(border_window) then | |
return | |
end | |
local new_width, new_height, new_row, new_col = get_window_pos() | |
api.nvim_win_set_config(border_window, | |
{ width = new_width + 2, height = new_height + 2, relative = 'editor', row = new_row - 1, col = new_col - 1, }) | |
api.nvim_win_set_config(win, | |
{ width = new_width, height = new_height, relative = 'editor', row = new_row, col = new_col, }) | |
end | |
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, if you try it out, the position/size after resizing would be messed up, I think it is some race between the event and when the new size detail gets updated
It causes the contents of the window to shift too much left
There is probably a better solution
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without defering, this is how it looks - I'm pretty sure it looked worse for me yesterday, but maybe it was during playing around with parameters. Without the delay it's still a bit wonky - notice how LG expands outside the border window
Screen.Recording.2024-02-13.at.10.53.25.mov
Also honestly this is the first time I've played around with nvim floating windows, perhaps there is a more reliable way to do this, which involves checking a condition and not using an arbitrary amount of time, but I wouldn't know what to check against (e.g. some boolean that says the ui updates are ready), so any ideas would be appreciated and I would love to play around with it and update the PR :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually on another computer, the defer doesn't fix the problem, and it really jumps around much. See:
Screen.Recording.2024-02-13.at.15.06.21.mov
Don't know why this happens or how to solve it :(
Hey, I was just facing this issue and just saw they are already a fix for it, thanks @chenasraf. |
It's pretty much working, the problem is it's kind of wonky and isn't very consistent. You can see the discussion here - something about the resizing logic between the 2 systems is not aligning right. Honestly I have no idea why this happens, if you want to give it a go, please be my guest :) I am currently using my own fork which is exactly only this PR added, so I am using it daily myself, but I'm not sure it's good enough quality to have for everyone yet. |
https://github.com/nvim-telescope/telescope.nvim Neovim telescope does window resizing very well, maybe worth trying to take a look at their implementation? |
Fixes #116
Screen.Recording.2024-02-13.at.3.51.17.mov
The
defer
is a bit of a hack, but otherwise the new size doesn't get enough time to be properly registered. It still sometimes messes up and positions itself slightly off sometimes if I try to do it several times fast, so maybe the delay needs to be adjusted, some debounce added, or we might want to find a different method for ensuring the window has the correct size.