aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Edmund Lazo <jan.lazo@mail.utoronto.ca>2021-03-01 23:01:09 -0500
committerJan Edmund Lazo <jan.lazo@mail.utoronto.ca>2021-03-02 00:35:52 -0500
commitf32acc70e84a3ea4a61e856e4d723ccc433e687c (patch)
tree0744a8c90289f7a7c98c0c5b242e3cd13b4d50c4
parenta5bacdbfb4f10652598d45e339c9f670b477ac8d (diff)
downloadrneovim-f32acc70e84a3ea4a61e856e4d723ccc433e687c.tar.gz
rneovim-f32acc70e84a3ea4a61e856e4d723ccc433e687c.tar.bz2
rneovim-f32acc70e84a3ea4a61e856e4d723ccc433e687c.zip
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) https://github.com/vim/vim/commit/746670604a60cb0356b56c112ffb6d297c679099
-rw-r--r--runtime/doc/options.txt4
-rw-r--r--src/nvim/ex_cmds2.c3
-rw-r--r--src/nvim/globals.h7
-rw-r--r--src/nvim/testdir/test_options.vim19
-rw-r--r--src/nvim/window.c10
-rw-r--r--test/functional/legacy/options_spec.lua28
6 files changed, 66 insertions, 5 deletions
diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt
index 73ec5af28e..c4d5df84cf 100644
--- a/runtime/doc/options.txt
+++ b/runtime/doc/options.txt
@@ -4856,7 +4856,9 @@ A jump table for the options with a short description can be found at |Q_op|.
local to window
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
- 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
height with ":set scroll=0".
diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c
index c24ecde096..c4c18c4324 100644
--- a/src/nvim/ex_cmds2.c
+++ b/src/nvim/ex_cmds2.c
@@ -3024,6 +3024,7 @@ void scriptnames_slash_adjust(void)
# endif
/// 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)
{
*should_free = false;
@@ -3039,6 +3040,8 @@ char_u *get_scriptname(LastSet last_set, bool *should_free)
return (char_u *)_("environment variable");
case SID_ERROR:
return (char_u *)_("error handler");
+ case SID_WINLAYOUT:
+ return (char_u *)_("changed window size");
case SID_LUA:
return (char_u *)_("Lua");
case SID_API_CLIENT:
diff --git a/src/nvim/globals.h b/src/nvim/globals.h
index 4733a24d5a..7b8e809de7 100644
--- a/src/nvim/globals.h
+++ b/src/nvim/globals.h
@@ -333,9 +333,10 @@ EXTERN int garbage_collect_at_exit INIT(= false);
#define SID_ENV -4 // for sourcing environment variable
#define SID_ERROR -5 // option was reset because of an error
#define SID_NONE -6 // don't set scriptID
-#define SID_LUA -7 // for Lua scripts/chunks
-#define SID_API_CLIENT -8 // for API clients
-#define SID_STR -9 // for sourcing a string
+#define SID_WINLAYOUT -7 // changing window size
+#define SID_LUA -8 // for Lua scripts/chunks
+#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.
EXTERN sctx_T current_sctx INIT(= { 0 COMMA 0 COMMA 0 });
diff --git a/src/nvim/testdir/test_options.vim b/src/nvim/testdir/test_options.vim
index 717a073937..1202b842fd 100644
--- a/src/nvim/testdir/test_options.vim
+++ b/src/nvim/testdir/test_options.vim
@@ -636,4 +636,23 @@ func Test_isfname_with_options()
setlocal keywordprg&
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
diff --git a/src/nvim/window.c b/src/nvim/window.c
index 7c74d43baf..0f717a2f90 100644
--- a/src/nvim/window.c
+++ b/src/nvim/window.c
@@ -5960,9 +5960,17 @@ void win_new_width(win_T *wp, int width)
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;
- if (wp->w_p_scr == 0)
+ if (wp->w_p_scr == 0) {
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;
+ }
}
/*
diff --git a/test/functional/legacy/options_spec.lua b/test/functional/legacy/options_spec.lua
index 598674dbeb..d7f5df3a1e 100644
--- a/test/functional/legacy/options_spec.lua
+++ b/test/functional/legacy/options_spec.lua
@@ -41,4 +41,32 @@ describe('set', function()
]])
matches('E36: Not enough room', exc_exec('set wmh=1'))
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)