feat(api): add nvim_win_resize()

Ref #6645

Problem:
When a window is resized it takes space from the window right/below first,
and only falls back to the window left/above when there is no more room.
Sometimes a user wants the space to come from a specific direction.

Solution:
Add nvim_win_resize(win, width, height, {anchor}) which resizes a window
with a choosable anchor edge, letting a window grow leftwards or upwards
by taking space from the window to the left or above first. The default
anchor reproduces nvim_win_set_width()/nvim_win_set_height().
This commit is contained in:
XiaowenHu96
2026-06-27 10:41:12 +08:00
parent 08a1228f82
commit ce718e31f4
17 changed files with 527 additions and 177 deletions

View File

@@ -677,7 +677,7 @@ local function update_popup_window(winid, bufnr, kind)
vim.treesitter.start(bufnr, kind)
end
local all = api.nvim_win_text_height(winid, {}).all
api.nvim_win_set_height(winid, all)
api.nvim_win_resize(winid, -1, all, {})
end
end

View File

@@ -1625,7 +1625,7 @@ function M.open_floating_preview(contents, syntax, opts)
local win_height = api.nvim_win_get_height(floating_winnr)
local text_height = api.nvim_win_text_height(floating_winnr, { max_height = win_height }).all
if text_height < win_height then
api.nvim_win_set_height(floating_winnr, text_height)
api.nvim_win_resize(floating_winnr, -1, text_height, {})
end
end
end