diff --git a/src/nvim/option.c b/src/nvim/option.c index 68c59c1c6b..7f2bbeb154 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -7151,7 +7151,7 @@ int64_t get_scrolloff_value(win_T *wp) /// global value when appropriate. int64_t get_scrolloffpad_value(win_T *wp) { - return wp->w_p_sop == -1 ? p_sop : curwin->w_p_sop; + return wp->w_p_sop == -1 ? p_sop : wp->w_p_sop; } /// Return the effective 'sidescrolloff' value for the current window, using the diff --git a/test/functional/legacy/scroll_opt_spec.lua b/test/functional/legacy/scroll_opt_spec.lua index 2677fcae4a..88378d8877 100644 --- a/test/functional/legacy/scroll_opt_spec.lua +++ b/test/functional/legacy/scroll_opt_spec.lua @@ -1599,6 +1599,23 @@ describe('scrolloffpad', function() exec('normal! G') screen:expect(s1) end) + + it("uses the target window's value, not the current window's", function() + exec([[ + set scrolloff=10 scrolloffpad=0 + enew! + call setline(1, map(range(1, 100), 'printf("line %d", v:val)')) + split + setlocal scrolloffpad=5 + normal! G + wincmd j + silent 1,60d + ]]) + -- The upper window turned 'scrolloffpad' on for itself, so its own value + -- decides how far its cursor is padded from the end of the buffer, even + -- though the current window leaves the option at the global 0. + t.eq(36, n.fn.line('w0', n.fn.win_getid(1))) + end) end) describe('scroll_cursor_halfway()', function()