vim-patch:8.2.2236: 'scroll' option can change when setting the statusline

Problem:    'scroll' option can change when setting the statusline or tabline
            but the option context is not updated.
Solution:   Update the script context when the scroll option is changed as a
            side effect. (Christian Brabandt, closes vim/vim#7533)
746670604a
This commit is contained in:
Jan Edmund Lazo
2021-03-01 23:01:09 -05:00
parent a5bacdbfb4
commit f32acc70e8
6 changed files with 66 additions and 5 deletions

View File

@@ -4856,7 +4856,9 @@ A jump table for the options with a short description can be found at |Q_op|.
local to window local to window
Number of lines to scroll with CTRL-U and CTRL-D commands. Will be Number of lines to scroll with CTRL-U and CTRL-D commands. Will be
set to half the number of lines in the window when the window size set to half the number of lines in the window when the window size
changes. If you give a count to the CTRL-U or CTRL-D command it will changes. This may happen when enabling the |status-line| or
'tabline' option after setting the 'scroll' option.
If you give a count to the CTRL-U or CTRL-D command it will
be used as the new value for 'scroll'. Reset to half the window be used as the new value for 'scroll'. Reset to half the window
height with ":set scroll=0". height with ":set scroll=0".

View File

@@ -3024,6 +3024,7 @@ void scriptnames_slash_adjust(void)
# endif # endif
/// Get a pointer to a script name. Used for ":verbose set". /// Get a pointer to a script name. Used for ":verbose set".
/// Message appended to "Last set from "
char_u *get_scriptname(LastSet last_set, bool *should_free) char_u *get_scriptname(LastSet last_set, bool *should_free)
{ {
*should_free = false; *should_free = false;
@@ -3039,6 +3040,8 @@ char_u *get_scriptname(LastSet last_set, bool *should_free)
return (char_u *)_("environment variable"); return (char_u *)_("environment variable");
case SID_ERROR: case SID_ERROR:
return (char_u *)_("error handler"); return (char_u *)_("error handler");
case SID_WINLAYOUT:
return (char_u *)_("changed window size");
case SID_LUA: case SID_LUA:
return (char_u *)_("Lua"); return (char_u *)_("Lua");
case SID_API_CLIENT: case SID_API_CLIENT:

View File

@@ -333,9 +333,10 @@ EXTERN int garbage_collect_at_exit INIT(= false);
#define SID_ENV -4 // for sourcing environment variable #define SID_ENV -4 // for sourcing environment variable
#define SID_ERROR -5 // option was reset because of an error #define SID_ERROR -5 // option was reset because of an error
#define SID_NONE -6 // don't set scriptID #define SID_NONE -6 // don't set scriptID
#define SID_LUA -7 // for Lua scripts/chunks #define SID_WINLAYOUT -7 // changing window size
#define SID_API_CLIENT -8 // for API clients #define SID_LUA -8 // for Lua scripts/chunks
#define SID_STR -9 // for sourcing a string #define SID_API_CLIENT -9 // for API clients
#define SID_STR -10 // for sourcing a string
// Script CTX being sourced or was sourced to define the current function. // Script CTX being sourced or was sourced to define the current function.
EXTERN sctx_T current_sctx INIT(= { 0 COMMA 0 COMMA 0 }); EXTERN sctx_T current_sctx INIT(= { 0 COMMA 0 COMMA 0 });

View File

@@ -636,4 +636,23 @@ func Test_isfname_with_options()
setlocal keywordprg& setlocal keywordprg&
endfunc endfunc
" Test that resetting laststatus does change scroll option
func Test_opt_reset_scroll()
" See test/functional/legacy/options_spec.lua
CheckRunVimInTerminal
let vimrc =<< trim [CODE]
set scroll=2
set laststatus=2
[CODE]
call writefile(vimrc, 'Xscroll')
let buf = RunVimInTerminal('-S Xscroll', {'rows': 16, 'cols': 45})
call term_sendkeys(buf, ":verbose set scroll?\n")
call WaitForAssert({-> assert_match('Last set.*window size', term_getline(buf, 15))})
call assert_match('^\s*scroll=7$', term_getline(buf, 14))
call StopVimInTerminal(buf)
" clean up
call delete('Xscroll')
endfunc
" vim: shiftwidth=2 sts=2 expandtab " vim: shiftwidth=2 sts=2 expandtab

View File

@@ -5960,10 +5960,18 @@ void win_new_width(win_T *wp, int width)
void win_comp_scroll(win_T *wp) void win_comp_scroll(win_T *wp)
{ {
const long old_w_p_scr = wp->w_p_scr;
wp->w_p_scr = wp->w_height / 2; wp->w_p_scr = wp->w_height / 2;
if (wp->w_p_scr == 0) if (wp->w_p_scr == 0) {
wp->w_p_scr = 1; wp->w_p_scr = 1;
} }
if (wp->w_p_scr != old_w_p_scr) {
// Used by "verbose set scroll".
wp->w_p_script_ctx[WV_SCROLL].script_ctx.sc_sid = SID_WINLAYOUT;
wp->w_p_script_ctx[WV_SCROLL].script_ctx.sc_lnum = 0;
}
}
/* /*
* command_height: called whenever p_ch has been changed * command_height: called whenever p_ch has been changed

View File

@@ -41,4 +41,32 @@ describe('set', function()
]]) ]])
matches('E36: Not enough room', exc_exec('set wmh=1')) matches('E36: Not enough room', exc_exec('set wmh=1'))
end) end)
it('scroll works', function()
local screen = Screen.new(42, 16)
screen:attach()
source([[
set scroll=2
set laststatus=2
]])
command('verbose set scroll?')
screen:expect([[
|
~ |
~ |
~ |
~ |
~ |
~ |
~ |
~ |
~ |
~ |
~ |
|
scroll=7 |
Last set from changed window size |
Press ENTER or type command to continue^ |
]])
end)
end) end)