mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Merge pull request #18629 from famiu/fix/ui/winbar
fix(ui): make `winbar` properly equalize window heights for local value
This commit is contained in:
commit
69853a622a
@ -2033,6 +2033,37 @@ void win_move_after(win_T *win1, win_T *win2)
|
|||||||
win2->w_pos_changed = true;
|
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.
|
/// Make all windows the same height.
|
||||||
///'next_curwin' will soon be the current window, make sure it has enough rows.
|
///'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 {
|
} else {
|
||||||
extra_sep = 0;
|
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);
|
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 {
|
} else {
|
||||||
// These windows don't use up room.
|
// These windows don't use up room.
|
||||||
totwincount -= (n + (fr->fr_next == NULL
|
totwincount -= get_maximum_wincount(fr, (n + (fr->fr_next == NULL ? extra_sep : 0)));
|
||||||
? extra_sep : 0)) / (p_wmh + STATUS_HEIGHT + global_winbar_height());
|
|
||||||
}
|
}
|
||||||
room -= new_size - n;
|
room -= new_size - n;
|
||||||
if (room < 0) {
|
if (room < 0) {
|
||||||
@ -2312,8 +2342,7 @@ static void win_equal_rec(win_T *next_curwin, bool current, frame_T *topfr, int
|
|||||||
} else {
|
} else {
|
||||||
// Compute the maximum number of windows vert. in "fr".
|
// Compute the maximum number of windows vert. in "fr".
|
||||||
n = frame_minheight(fr, NOWIN);
|
n = frame_minheight(fr, NOWIN);
|
||||||
wincount = (n + (fr->fr_next == NULL ? extra_sep : 0))
|
wincount = get_maximum_wincount(fr, (n + (fr->fr_next == NULL ? extra_sep : 0)));
|
||||||
/ (p_wmh + STATUS_HEIGHT + global_winbar_height());
|
|
||||||
m = frame_minheight(fr, next_curwin);
|
m = frame_minheight(fr, next_curwin);
|
||||||
if (has_next_curwin) {
|
if (has_next_curwin) {
|
||||||
hnc = frame_has_win(fr, next_curwin);
|
hnc = frame_has_win(fr, next_curwin);
|
||||||
|
@ -345,4 +345,24 @@ describe('winbar', function()
|
|||||||
]])
|
]])
|
||||||
eq(1, meths.get_option('cmdheight'))
|
eq(1, meths.get_option('cmdheight'))
|
||||||
end)
|
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)
|
end)
|
||||||
|
Loading…
Reference in New Issue
Block a user