vim-patch:8.1.0706: introduce :redrawtabline #10570

Problem:    Tabline is not always redrawn when something that is used in
            'tabline' changes.
Solution:   Add ":redrawtabline" so that a plugin can at least cause the
            redraw when needed.
e12bab3144
This commit is contained in:
Jan Edmund Lazo
2019-07-22 06:25:07 -04:00
committed by Justin M. Keyes
parent f8684bf6b9
commit 39549159fe
6 changed files with 61 additions and 9 deletions

View File

@@ -6027,6 +6027,8 @@ A jump table for the options with a short description can be found at |Q_op|.
the text to be displayed. Use "%1T" for the first label, "%2T" for the text to be displayed. Use "%1T" for the first label, "%2T" for
the second one, etc. Use "%X" items for closing labels. the second one, etc. Use "%X" items for closing labels.
When changing something that is used in 'tabline' that does not
trigger it to be updated, use |:redrawtabline|.
This option cannot be set in a modeline when 'modelineexpr' is off. This option cannot be set in a modeline when 'modelineexpr' is off.
Keep in mind that only one of the tab pages is the current one, others Keep in mind that only one of the tab pages is the current one, others

View File

@@ -31,6 +31,11 @@ CTRL-L Clears and redraws the screen. The redraw may happen
Useful if 'statusline' includes an item that doesn't Useful if 'statusline' includes an item that doesn't
cause automatic updating. cause automatic updating.
*:redrawt* *:redrawtabline*
:redrawt[abline] Redraw the tabline. Useful to update the tabline when
'tabline' includes an item that doesn't trigger
automatic updating.
*N<Del>* *N<Del>*
<Del> When entering a number: Remove the last digit. <Del> When entering a number: Remove the last digit.
Note: if you like to use <BS> for this, add this Note: if you like to use <BS> for this, add this

View File

@@ -2150,6 +2150,12 @@ return {
addr_type=ADDR_LINES, addr_type=ADDR_LINES,
func='ex_redrawstatus', func='ex_redrawstatus',
}, },
{
command='redrawtabline',
flags=bit.bor(TRLBAR, CMDWIN),
addr_type=ADDR_LINES,
func='ex_redrawtabline',
},
{ {
command='registers', command='registers',
flags=bit.bor(EXTRA, NOTRLCOM, TRLBAR, CMDWIN), flags=bit.bor(EXTRA, NOTRLCOM, TRLBAR, CMDWIN),

View File

@@ -7874,6 +7874,22 @@ static void ex_redrawstatus(exarg_T *eap)
ui_flush(); ui_flush();
} }
// ":redrawtabline": force redraw of the tabline
static void ex_redrawtabline(exarg_T *eap FUNC_ATTR_UNUSED)
{
const int r = RedrawingDisabled;
const int p = p_lz;
RedrawingDisabled = 0;
p_lz = false;
draw_tabline();
RedrawingDisabled = r;
p_lz = p;
ui_flush();
}
static void close_redir(void) static void close_redir(void)
{ {
if (redir_fd != NULL) { if (redir_fd != NULL) {

View File

@@ -6650,7 +6650,7 @@ static void recording_mode(int attr)
/* /*
* Draw the tab pages line at the top of the Vim window. * Draw the tab pages line at the top of the Vim window.
*/ */
static void draw_tabline(void) void draw_tabline(void)
{ {
int tabcount = 0; int tabcount = 0;
int tabwidth = 0; int tabwidth = 0;

View File

@@ -1,19 +1,22 @@
function! TablineWithCaughtError()
source shared.vim
func TablineWithCaughtError()
let s:func_in_tabline_called = 1 let s:func_in_tabline_called = 1
try try
call eval('unknown expression') call eval('unknown expression')
catch catch
endtry endtry
return '' return ''
endfunction endfunc
function! TablineWithError() func TablineWithError()
let s:func_in_tabline_called = 1 let s:func_in_tabline_called = 1
call eval('unknown expression') call eval('unknown expression')
return '' return ''
endfunction endfunc
function! Test_caught_error_in_tabline() func Test_caught_error_in_tabline()
let showtabline_save = &showtabline let showtabline_save = &showtabline
set showtabline=2 set showtabline=2
let s:func_in_tabline_called = 0 let s:func_in_tabline_called = 0
@@ -24,9 +27,9 @@ function! Test_caught_error_in_tabline()
call assert_equal(tabline, &tabline) call assert_equal(tabline, &tabline)
set tabline= set tabline=
let &showtabline = showtabline_save let &showtabline = showtabline_save
endfunction endfunc
function! Test_tabline_will_be_disabled_with_error() func Test_tabline_will_be_disabled_with_error()
let showtabline_save = &showtabline let showtabline_save = &showtabline
set showtabline=2 set showtabline=2
let s:func_in_tabline_called = 0 let s:func_in_tabline_called = 0
@@ -40,4 +43,24 @@ function! Test_tabline_will_be_disabled_with_error()
call assert_equal('', &tabline) call assert_equal('', &tabline)
set tabline= set tabline=
let &showtabline = showtabline_save let &showtabline = showtabline_save
endfunction endfunc
func Test_redrawtabline()
if has('gui')
set guioptions-=e
endif
let showtabline_save = &showtabline
set showtabline=2
set tabline=%{bufnr('$')}
edit Xtabline1
edit Xtabline2
redraw
call assert_match(bufnr('$') . '', Screenline(1))
au BufAdd * redrawtabline
badd Xtabline3
call assert_match(bufnr('$') . '', Screenline(1))
set tabline=
let &showtabline = showtabline_save
au! Bufadd
endfunc