mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Merge pull request #18776 from famiu/fix/winbar_noroom
fix(winbar): only allow adding winbar when there is space
This commit is contained in:
commit
0dd3798dbb
@ -6620,17 +6620,15 @@ static void win_remove_status_line(win_T *wp, bool add_hsep)
|
|||||||
wp->w_status_click_defs = NULL;
|
wp->w_status_click_defs = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Look for resizable frames and take lines from them to make room for the statusline
|
// Look for a horizontally resizable frame, starting with frame "fr".
|
||||||
static void resize_frame_for_status(frame_T *fr)
|
// Returns NULL if there are no resizable frames.
|
||||||
|
static frame_T *find_horizontally_resizable_frame(frame_T *fr)
|
||||||
{
|
{
|
||||||
// Find a frame to take a line from.
|
|
||||||
frame_T *fp = fr;
|
frame_T *fp = fr;
|
||||||
win_T *wp = fr->fr_win;
|
|
||||||
|
|
||||||
while (fp->fr_height <= frame_minheight(fp, NULL)) {
|
while (fp->fr_height <= frame_minheight(fp, NULL)) {
|
||||||
if (fp == topframe) {
|
if (fp == topframe) {
|
||||||
emsg(_(e_noroom));
|
return NULL;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
// In a column of frames: go to frame above. If already at
|
// In a column of frames: go to frame above. If already at
|
||||||
// the top or in a row of frames: go to parent.
|
// the top or in a row of frames: go to parent.
|
||||||
@ -6640,13 +6638,49 @@ static void resize_frame_for_status(frame_T *fr)
|
|||||||
fp = fp->fr_parent;
|
fp = fp->fr_parent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (fp != fr) {
|
|
||||||
|
return fp;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Look for resizable frames and take lines from them to make room for the statusline.
|
||||||
|
// @return Success or failure.
|
||||||
|
static bool resize_frame_for_status(frame_T *fr)
|
||||||
|
{
|
||||||
|
win_T *wp = fr->fr_win;
|
||||||
|
frame_T *fp = find_horizontally_resizable_frame(fr);
|
||||||
|
|
||||||
|
if (fp == NULL) {
|
||||||
|
emsg(_(e_noroom));
|
||||||
|
return false;
|
||||||
|
} else if (fp != fr) {
|
||||||
frame_new_height(fp, fp->fr_height - 1, false, false);
|
frame_new_height(fp, fp->fr_height - 1, false, false);
|
||||||
frame_fix_height(wp);
|
frame_fix_height(wp);
|
||||||
(void)win_comp_pos();
|
(void)win_comp_pos();
|
||||||
} else {
|
} else {
|
||||||
win_new_height(wp, wp->w_height - 1);
|
win_new_height(wp, wp->w_height - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Look for resizable frames and take lines from them to make room for the winbar.
|
||||||
|
// @return Success or failure.
|
||||||
|
static bool resize_frame_for_winbar(frame_T *fr)
|
||||||
|
{
|
||||||
|
win_T *wp = fr->fr_win;
|
||||||
|
frame_T *fp = find_horizontally_resizable_frame(fr);
|
||||||
|
|
||||||
|
if (fp == NULL || fp == fr) {
|
||||||
|
emsg(_(e_noroom));
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
frame_new_height(fp, fp->fr_height - 1, false, false);
|
||||||
|
win_new_height(wp, wp->w_height + 1);
|
||||||
|
frame_fix_height(wp);
|
||||||
|
win_comp_pos();
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void last_status_rec(frame_T *fr, bool statusline, bool is_stl_global)
|
static void last_status_rec(frame_T *fr, bool statusline, bool is_stl_global)
|
||||||
@ -6664,7 +6698,9 @@ static void last_status_rec(frame_T *fr, bool statusline, bool is_stl_global)
|
|||||||
} else if (wp->w_status_height == 0 && !is_stl_global && statusline) {
|
} else if (wp->w_status_height == 0 && !is_stl_global && statusline) {
|
||||||
// Add statusline to window if needed
|
// Add statusline to window if needed
|
||||||
wp->w_status_height = STATUS_HEIGHT;
|
wp->w_status_height = STATUS_HEIGHT;
|
||||||
resize_frame_for_status(fr);
|
if (!resize_frame_for_status(fr)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
comp_col();
|
comp_col();
|
||||||
}
|
}
|
||||||
} else if (wp->w_status_height != 0 && is_stl_global) {
|
} else if (wp->w_status_height != 0 && is_stl_global) {
|
||||||
@ -6695,6 +6731,14 @@ void set_winbar(void)
|
|||||||
: ((*p_wbr != NUL || *wp->w_p_wbr != NUL) ? 1 : 0);
|
: ((*p_wbr != NUL || *wp->w_p_wbr != NUL) ? 1 : 0);
|
||||||
|
|
||||||
if (wp->w_winbar_height != winbar_height) {
|
if (wp->w_winbar_height != winbar_height) {
|
||||||
|
if (winbar_height == 1 && wp->w_height_inner <= 1) {
|
||||||
|
if (wp->w_floating) {
|
||||||
|
emsg(_(e_noroom));
|
||||||
|
continue;
|
||||||
|
} else if (!resize_frame_for_winbar(wp->w_frame)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
wp->w_winbar_height = winbar_height;
|
wp->w_winbar_height = winbar_height;
|
||||||
win_set_inner_size(wp);
|
win_set_inner_size(wp);
|
||||||
wp->w_redr_status = wp->w_redr_status || winbar_height;
|
wp->w_redr_status = wp->w_redr_status || winbar_height;
|
||||||
|
@ -7,6 +7,7 @@ local meths = helpers.meths
|
|||||||
local eq = helpers.eq
|
local eq = helpers.eq
|
||||||
local poke_eventloop = helpers.poke_eventloop
|
local poke_eventloop = helpers.poke_eventloop
|
||||||
local feed = helpers.feed
|
local feed = helpers.feed
|
||||||
|
local pcall_err = helpers.pcall_err
|
||||||
|
|
||||||
describe('winbar', function()
|
describe('winbar', function()
|
||||||
local screen
|
local screen
|
||||||
@ -28,6 +29,7 @@ describe('winbar', function()
|
|||||||
})
|
})
|
||||||
meths.set_option('winbar', 'Set Up The Bars')
|
meths.set_option('winbar', 'Set Up The Bars')
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('works', function()
|
it('works', function()
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
{1:Set Up The Bars }|
|
{1:Set Up The Bars }|
|
||||||
@ -45,6 +47,7 @@ describe('winbar', function()
|
|||||||
|
|
|
|
||||||
]])
|
]])
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('works with custom \'fillchars\' value', function()
|
it('works with custom \'fillchars\' value', function()
|
||||||
command('set fillchars=wbr:+')
|
command('set fillchars=wbr:+')
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
@ -63,6 +66,7 @@ describe('winbar', function()
|
|||||||
|
|
|
|
||||||
]])
|
]])
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('works with custom highlight', function()
|
it('works with custom highlight', function()
|
||||||
command('hi WinBar guifg=red')
|
command('hi WinBar guifg=red')
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
@ -81,6 +85,7 @@ describe('winbar', function()
|
|||||||
|
|
|
|
||||||
]])
|
]])
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('works with splits', function()
|
it('works with splits', function()
|
||||||
command('hi WinBar guifg=red')
|
command('hi WinBar guifg=red')
|
||||||
command('hi WinBarNC guifg=blue')
|
command('hi WinBarNC guifg=blue')
|
||||||
@ -101,6 +106,7 @@ describe('winbar', function()
|
|||||||
|
|
|
|
||||||
]])
|
]])
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('works when switching value of \'winbar\'', function()
|
it('works when switching value of \'winbar\'', function()
|
||||||
command('belowright vsplit | split | split | set winbar=')
|
command('belowright vsplit | split | split | set winbar=')
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
@ -151,6 +157,7 @@ describe('winbar', function()
|
|||||||
|
|
|
|
||||||
]])
|
]])
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('can be ruler', function()
|
it('can be ruler', function()
|
||||||
insert [[
|
insert [[
|
||||||
just some
|
just some
|
||||||
@ -204,6 +211,7 @@ describe('winbar', function()
|
|||||||
|
|
|
|
||||||
]]}
|
]]}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('works with laststatus=3', function()
|
it('works with laststatus=3', function()
|
||||||
command('set laststatus=3')
|
command('set laststatus=3')
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
@ -495,4 +503,59 @@ describe('winbar', function()
|
|||||||
|
|
|
|
||||||
]])
|
]])
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('properly resizes window when there is no space in it', function()
|
||||||
|
command('set winbar= | 1split')
|
||||||
|
screen:expect([[
|
||||||
|
^ |
|
||||||
|
{4:[No Name] }|
|
||||||
|
|
|
||||||
|
{3:~ }|
|
||||||
|
{3:~ }|
|
||||||
|
{3:~ }|
|
||||||
|
{3:~ }|
|
||||||
|
{3:~ }|
|
||||||
|
{3:~ }|
|
||||||
|
{3:~ }|
|
||||||
|
{3:~ }|
|
||||||
|
{2:[No Name] }|
|
||||||
|
|
|
||||||
|
]])
|
||||||
|
command('set winbar=a')
|
||||||
|
screen:expect([[
|
||||||
|
{1:a }|
|
||||||
|
^ |
|
||||||
|
{4:[No Name] }|
|
||||||
|
{1:a }|
|
||||||
|
|
|
||||||
|
{3:~ }|
|
||||||
|
{3:~ }|
|
||||||
|
{3:~ }|
|
||||||
|
{3:~ }|
|
||||||
|
{3:~ }|
|
||||||
|
{3:~ }|
|
||||||
|
{2:[No Name] }|
|
||||||
|
|
|
||||||
|
]])
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('cannot be added unless there is room', function()
|
||||||
|
command('set winbar= | split | split | split | split | split')
|
||||||
|
screen:expect([[
|
||||||
|
^ |
|
||||||
|
{4:[No Name] }|
|
||||||
|
|
|
||||||
|
{2:[No Name] }|
|
||||||
|
|
|
||||||
|
{2:[No Name] }|
|
||||||
|
|
|
||||||
|
{2:[No Name] }|
|
||||||
|
|
|
||||||
|
{2:[No Name] }|
|
||||||
|
|
|
||||||
|
{2:[No Name] }|
|
||||||
|
|
|
||||||
|
]])
|
||||||
|
eq('Vim(set):E36: Not enough room', pcall_err(command, 'set winbar=test'))
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
Loading…
Reference in New Issue
Block a user