vim-patch:9.0.1568: with 'smoothscroll' cursor may move below botline

Problem:    With 'smoothscroll' cursor may move below botline.
Solution:   Call redraw_later() if needed,  Compute cursor row with adjusted
            condition. (Luuk van Baal, closes vim/vim#12415)

d49f646bf5
This commit is contained in:
Luuk van Baal 2023-05-19 18:42:54 +02:00
parent 02ef104d5b
commit cf0f83ebf0
3 changed files with 102 additions and 37 deletions

View File

@ -415,6 +415,8 @@ void update_topline(win_T *wp)
// When 'smoothscroll' is not set, should reset w_skipcol. // When 'smoothscroll' is not set, should reset w_skipcol.
if (!wp->w_p_sms) { if (!wp->w_p_sms) {
reset_skipcol(wp); reset_skipcol(wp);
} else if (wp->w_skipcol != 0) {
redraw_later(wp, UPD_SOME_VALID);
} }
// May need to set w_skipcol when cursor in w_topline. // May need to set w_skipcol when cursor in w_topline.
@ -659,7 +661,7 @@ static void curs_rows(win_T *wp)
i--; // hold at inserted lines i--; // hold at inserted lines
} }
} }
if (valid && (lnum != wp->w_topline || !win_may_fill(wp))) { if (valid && (lnum != wp->w_topline || (wp->w_skipcol == 0 && !win_may_fill(wp)))) {
lnum = wp->w_lines[i].wl_lastlnum + 1; lnum = wp->w_lines[i].wl_lastlnum + 1;
// Cursor inside folded lines, don't count this row // Cursor inside folded lines, don't count this row
if (lnum > wp->w_cursor.lnum) { if (lnum > wp->w_cursor.lnum) {

View File

@ -422,42 +422,15 @@ describe('smoothscroll', function()
| |
]]) ]])
feed('j') feed('j')
screen:expect([[ screen:expect_unchanged()
Line with some text with some text with |
some text with some text with some text |
with some text with some text |
^Line with some text with some text with |
some text with some text with some text |
with some text with some text |
@ |
|
]])
-- moving cursor down - whole bottom line shows -- moving cursor down - whole bottom line shows
feed('<C-E>j') feed('<C-E>j')
screen:expect([[ screen:expect_unchanged()
<<<h some text with some text |
Line with some text with some text with |
some text with some text with some text |
with some text with some text |
^Line with some text with some text with |
some text with some text with some text |
with some text with some text |
|
]])
feed('G') feed('G')
-- FIXME: different from vim onwards, this had in incorrect cursor position screen:expect_unchanged()
-- in vim but we show an eob line. feed('4<C-Y>G')
screen:expect([[ screen:expect_unchanged()
<<<h some text with some text | -- moving cursor up right after the <<< marker - no need to show whole line
Line with some text with some text with |
some text with some text with some text |
with some text with some text |
Line with some text with some text with |
some text with some text with some text |
^with some text with some text |
|
]])
-- moving cursor up right after the >>> marker - no need to show whole line
feed('2gj3l2k') feed('2gj3l2k')
screen:expect([[ screen:expect([[
<<<^h some text with some text | <<<^h some text with some text |
@ -469,7 +442,7 @@ describe('smoothscroll', function()
with some text with some text | with some text with some text |
| |
]]) ]])
-- moving cursor up where the >>> marker is - whole top line shows -- moving cursor up where the <<< marker is - whole top line shows
feed('2j02k') feed('2j02k')
screen:expect([[ screen:expect([[
^Line with some text with some text with | ^Line with some text with some text with |
@ -805,6 +778,67 @@ describe('smoothscroll', function()
]]) ]])
end) end)
-- oldtest: Test_smoothscroll_incsearch()
it("does not reset skipcol when doing incremental search on the same word", function()
screen:try_resize(40, 8)
screen:set_default_attr_ids({
[1] = {foreground = Screen.colors.Brown},
[2] = {foreground = Screen.colors.Blue1, bold = true},
[3] = {background = Screen.colors.Yellow1},
[4] = {reverse = true},
})
exec([[
set smoothscroll number scrolloff=0 incsearch
call setline(1, repeat([''], 20))
call setline(11, repeat('a', 100))
call setline(14, 'bbbb')
]])
feed('/b')
screen:expect([[
{2:<<<}{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaa |
{1: 12 } |
{1: 13 } |
{1: 14 }{4:b}{3:bbb} |
{1: 15 } |
{1: 16 } |
{1: 17 } |
/b^ |
]])
feed('b')
screen:expect([[
{2:<<<}{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaa |
{1: 12 } |
{1: 13 } |
{1: 14 }{4:bb}{3:bb} |
{1: 15 } |
{1: 16 } |
{1: 17 } |
/bb^ |
]])
feed('b')
screen:expect([[
{2:<<<}{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaa |
{1: 12 } |
{1: 13 } |
{1: 14 }{4:bbb}b |
{1: 15 } |
{1: 16 } |
{1: 17 } |
/bbb^ |
]])
feed('b')
screen:expect([[
{2:<<<}{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaa |
{1: 12 } |
{1: 13 } |
{1: 14 }{4:bbbb} |
{1: 15 } |
{1: 16 } |
{1: 17 } |
/bbbb^ |
]])
end)
it("works with virt_lines above and below", function() it("works with virt_lines above and below", function()
screen:try_resize(55, 7) screen:try_resize(55, 7)
exec([=[ exec([=[

View File

@ -257,11 +257,14 @@ func Test_smoothscroll_wrap_scrolloff_zero()
call term_sendkeys(buf, "G") call term_sendkeys(buf, "G")
call VerifyScreenDump(buf, 'Test_smooth_wrap_4', {}) call VerifyScreenDump(buf, 'Test_smooth_wrap_4', {})
" moving cursor up right after the >>> marker - no need to show whole line call term_sendkeys(buf, "4\<C-Y>G")
call VerifyScreenDump(buf, 'Test_smooth_wrap_4', {})
" moving cursor up right after the <<< marker - no need to show whole line
call term_sendkeys(buf, "2gj3l2k") call term_sendkeys(buf, "2gj3l2k")
call VerifyScreenDump(buf, 'Test_smooth_wrap_5', {}) call VerifyScreenDump(buf, 'Test_smooth_wrap_5', {})
" moving cursor up where the >>> marker is - whole top line shows " moving cursor up where the <<< marker is - whole top line shows
call term_sendkeys(buf, "2j02k") call term_sendkeys(buf, "2j02k")
call VerifyScreenDump(buf, 'Test_smooth_wrap_6', {}) call VerifyScreenDump(buf, 'Test_smooth_wrap_6', {})
@ -705,4 +708,30 @@ func Test_smoothscroll_eob()
call StopVimInTerminal(buf) call StopVimInTerminal(buf)
endfunc endfunc
" skipcol should not reset when doing incremental search on the same word
func Test_smoothscroll_incsearch()
CheckScreendump
let lines =<< trim END
set smoothscroll number scrolloff=0 incsearch
call setline(1, repeat([''], 20))
call setline(11, repeat('a', 100))
call setline(14, 'bbbb')
END
call writefile(lines, 'XSmoothIncsearch', 'D')
let buf = RunVimInTerminal('-S XSmoothIncsearch', #{rows: 8, cols:40})
call term_sendkeys(buf, "/b")
call VerifyScreenDump(buf, 'Test_smooth_incsearch_1', {})
call term_sendkeys(buf, "b")
call VerifyScreenDump(buf, 'Test_smooth_incsearch_2', {})
call term_sendkeys(buf, "b")
call VerifyScreenDump(buf, 'Test_smooth_incsearch_3', {})
call term_sendkeys(buf, "b")
call VerifyScreenDump(buf, 'Test_smooth_incsearch_4', {})
call term_sendkeys(buf, "\<CR>")
call StopVimInTerminal(buf)
endfunc
" vim: shiftwidth=2 sts=2 expandtab " vim: shiftwidth=2 sts=2 expandtab