mirror of
https://github.com/folke/snacks.nvim
synced 2025-12-23 08:47:57 +00:00
fix(layout): provide parent win width/height when relative to win (#2346)
## Description
When a win is relative = "win" it should size itself relative to that
win's size. Currently this only happens correctly when the picker layout
is created. All subsequent updates, such as a toggle_preview action, can
potentially trigger calls to a function width/height opt with a
max_width and max_height smaller than was previously calculated. This
feeds into a recursive series of updates triggered by the WinResized
event triggering and updating with a yet smaller max_width or
max_height.
Additionally, because win.o.cols and win.o.lines is used,
relative/decimal dimensions would not calculate correctly in splits.
Screenshots are from a picker configured as
```
{
col = 1,
height = 0.9,
width = 0.9,
position = 'float',
relative = 'win',
}
```
**before**
<img width="1348" height="1358" alt="image"
src="https://github.com/user-attachments/assets/847b0565-afd0-4ca1-b44c-eb63e335afca"
/>
**after**
<img width="1354" height="1354" alt="image"
src="https://github.com/user-attachments/assets/064f25ae-ed17-42c8-8b34-f32652fab02d"
/>
This commit is contained in:
parent
99e01f07a0
commit
602393aed2
1 changed files with 7 additions and 2 deletions
|
|
@ -250,11 +250,16 @@ function M:update()
|
|||
bottom = (vim.o.cmdheight + (vim.o.laststatus == 3 and 1 or 0)) or 0
|
||||
top = (vim.o.showtabline == 2 or (vim.o.showtabline == 1 and #vim.api.nvim_list_tabpages() > 1)) and 1 or 0
|
||||
end
|
||||
|
||||
local parent_width = layout.relative == "win" and vim.api.nvim_win_get_width(self.root.opts.win or 0) or vim.o.columns
|
||||
local parent_height = layout.relative == "win" and vim.api.nvim_win_get_height(self.root.opts.win or 0)
|
||||
or vim.o.lines - top - bottom
|
||||
|
||||
self:update_box(layout, {
|
||||
col = 0,
|
||||
row = self.opts.fullscreen and self.split and top or 0, -- only needed for fullscreen splits
|
||||
width = vim.o.columns,
|
||||
height = vim.o.lines - top - bottom,
|
||||
width = parent_width,
|
||||
height = parent_height,
|
||||
})
|
||||
|
||||
-- fix fullscreen float layouts
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue