aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbfredl <bjorn.linse@gmail.com>2022-05-19 21:58:48 +0200
committerGitHub <noreply@github.com>2022-05-19 21:58:48 +0200
commit69853a622a1fa9b920171657a255648e532bd444 (patch)
treee9e6cdc4994938ea8531f724a597a36320dbc341
parentbb8d05f93220506d88f316b25b741d92a44ef973 (diff)
parent643cc94e7e8c0cc970c08a916baebb19075040e2 (diff)
downloadrneovim-69853a622a1fa9b920171657a255648e532bd444.tar.gz
rneovim-69853a622a1fa9b920171657a255648e532bd444.tar.bz2
rneovim-69853a622a1fa9b920171657a255648e532bd444.zip
Merge pull request #18629 from famiu/fix/ui/winbar
fix(ui): make `winbar` properly equalize window heights for local value
-rw-r--r--src/nvim/window.c39
-rw-r--r--test/functional/ui/winbar_spec.lua20
2 files changed, 54 insertions, 5 deletions
diff --git a/src/nvim/window.c b/src/nvim/window.c
index 9c9b1fe176..4076bb2531 100644
--- a/src/nvim/window.c
+++ b/src/nvim/window.c
@@ -2033,6 +2033,37 @@ void win_move_after(win_T *win1, win_T *win2)
win2->w_pos_changed = true;
}
+/// Compute maximum number of windows that can fit within "height" in frame "fr".
+static int get_maximum_wincount(frame_T *fr, int height)
+{
+ if (fr->fr_layout != FR_COL) {
+ return (height / (p_wmh + STATUS_HEIGHT + frame2win(fr)->w_winbar_height));
+ } else if (global_winbar_height()) {
+ // If winbar is globally enabled, no need to check each window for it.
+ return (height / (p_wmh + STATUS_HEIGHT + 1));
+ }
+
+ frame_T *frp;
+ int total_wincount = 0;
+
+ // First, try to fit all child frames of "fr" into "height"
+ FOR_ALL_FRAMES(frp, fr->fr_child) {
+ win_T *wp = frame2win(frp);
+
+ if (height < (p_wmh + STATUS_HEIGHT + wp->w_winbar_height)) {
+ break;
+ }
+ height -= p_wmh + STATUS_HEIGHT + wp->w_winbar_height;
+ total_wincount += 1;
+ }
+
+ // If we still have enough room for more windows, just use the default winbar height (which is 0)
+ // in order to get the amount of windows that'd fit in the remaining space
+ total_wincount += height / (p_wmh + STATUS_HEIGHT);
+
+ return total_wincount;
+}
+
/// Make all windows the same height.
///'next_curwin' will soon be the current window, make sure it has enough rows.
///
@@ -2232,7 +2263,7 @@ static void win_equal_rec(win_T *next_curwin, bool current, frame_T *topfr, int
} else {
extra_sep = 0;
}
- totwincount = (n + extra_sep) / (p_wmh + STATUS_HEIGHT + global_winbar_height());
+ totwincount = get_maximum_wincount(topfr, n + extra_sep);
has_next_curwin = frame_has_win(topfr, next_curwin);
/*
@@ -2266,8 +2297,7 @@ static void win_equal_rec(win_T *next_curwin, bool current, frame_T *topfr, int
}
} else {
// These windows don't use up room.
- totwincount -= (n + (fr->fr_next == NULL
- ? extra_sep : 0)) / (p_wmh + STATUS_HEIGHT + global_winbar_height());
+ totwincount -= get_maximum_wincount(fr, (n + (fr->fr_next == NULL ? extra_sep : 0)));
}
room -= new_size - n;
if (room < 0) {
@@ -2312,8 +2342,7 @@ static void win_equal_rec(win_T *next_curwin, bool current, frame_T *topfr, int
} else {
// Compute the maximum number of windows vert. in "fr".
n = frame_minheight(fr, NOWIN);
- wincount = (n + (fr->fr_next == NULL ? extra_sep : 0))
- / (p_wmh + STATUS_HEIGHT + global_winbar_height());
+ wincount = get_maximum_wincount(fr, (n + (fr->fr_next == NULL ? extra_sep : 0)));
m = frame_minheight(fr, next_curwin);
if (has_next_curwin) {
hnc = frame_has_win(fr, next_curwin);
diff --git a/test/functional/ui/winbar_spec.lua b/test/functional/ui/winbar_spec.lua
index bf99cd6117..af7736293c 100644
--- a/test/functional/ui/winbar_spec.lua
+++ b/test/functional/ui/winbar_spec.lua
@@ -345,4 +345,24 @@ describe('winbar', function()
]])
eq(1, meths.get_option('cmdheight'))
end)
+ it('properly equalizes window height for window-local value', function()
+ command('set equalalways | set winbar= | setlocal winbar=a | split')
+ command('setlocal winbar= | split')
+ command('setlocal winbar=b | split')
+ screen:expect([[
+ {1:b }|
+ ^ |
+ {4:[No Name] }|
+ {1:b }|
+ |
+ {2:[No Name] }|
+ |
+ {3:~ }|
+ {2:[No Name] }|
+ {1:a }|
+ |
+ {2:[No Name] }|
+ |
+ ]])
+ end)
end)