From 7f5b5d34cfeb9428b9a213cb75646f1a82f3c60f Mon Sep 17 00:00:00 2001 From: luukvbaal Date: Fri, 11 Jul 2025 18:53:30 +0200 Subject: [PATCH] fix(window): don't store invalid height in window config (#34885) Problem: When 'winminheight' is zero and the window height is set to zero, the actual height is clamped whereas the stored config value is not. Reciprocal window configuration through nvim_win_get_config() then results in an error. Solution: Also clamp the stored dimensions in the window config. --- src/nvim/ui.c | 4 ++-- src/nvim/window.c | 2 +- test/functional/ui/float_spec.lua | 7 +++++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/nvim/ui.c b/src/nvim/ui.c index 541348e46b..0df724c131 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -724,8 +724,8 @@ void ui_grid_resize(handle_T grid_handle, int width, int height, Error *err) if (wp->w_floating) { if (width != wp->w_width || height != wp->w_height) { - wp->w_config.width = width; - wp->w_config.height = height; + wp->w_config.width = MAX(width, 1); + wp->w_config.height = MAX(height, 1); win_config_float(wp, wp->w_config); } } else { diff --git a/src/nvim/window.c b/src/nvim/window.c index 602bba7e13..92b8eab184 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -5854,7 +5854,7 @@ void win_setheight_win(int height, win_T *win) height = MAX(height, (int)(win == curwin ? MAX(p_wmh, 1) : p_wmh) + win->w_winbar_height); if (win->w_floating) { - win->w_config.height = height; + win->w_config.height = MAX(height, 1); win_config_float(win, win->w_config); redraw_later(win, UPD_VALID); } else { diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua index 19d38736b6..9eb2b750f2 100644 --- a/test/functional/ui/float_spec.lua +++ b/test/functional/ui/float_spec.lua @@ -923,6 +923,13 @@ describe('float window', function() assert_alive() end) + it("no error for zero height with 'winminheight'", function() + local win = api.nvim_open_win(0, false, { relative = 'editor', row = 0, col = 0, height = 1, width = 1 }) + api.nvim_set_option_value('winminheight', 0, {}) + api.nvim_win_set_height(win, 0) + api.nvim_win_set_config(win, api.nvim_win_get_config(win)) + end) + local function with_ext_multigrid(multigrid) local screen, attrs before_each(function()