mirror of
https://github.com/neovim/neovim.git
synced 2024-12-20 03:05:11 -07:00
vim-patch:9.0.0673: first line wong with 'smoothscroll' and 'scrolloff' zero
Problem: First line not scrolled properly with 'smoothscroll' and
'scrolloff' zero and using "k".
Solution: Make sure the cursor position is visible.
46b54747c5
Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
parent
3a1973debc
commit
d95697d6d4
@ -203,7 +203,7 @@ void update_topline(win_T *wp)
|
||||
bool check_topline = false;
|
||||
// If the cursor is above or near the top of the window, scroll the window
|
||||
// to show the line the cursor is in, with 'scrolloff' context.
|
||||
if (wp->w_topline > 1) {
|
||||
if (wp->w_topline > 1 || wp->w_skipcol > 0) {
|
||||
// If the cursor is above topline, scrolling is always needed.
|
||||
// If the cursor is far below topline and there is no folding,
|
||||
// scrolling down is never needed.
|
||||
@ -211,6 +211,15 @@ void update_topline(win_T *wp)
|
||||
check_topline = true;
|
||||
} else if (check_top_offset()) {
|
||||
check_topline = true;
|
||||
} else if (wp->w_skipcol > 0 && wp->w_cursor.lnum == wp->w_topline) {
|
||||
colnr_T vcol;
|
||||
|
||||
// check the cursor position is visible. Add 3 for the ">>>"
|
||||
// displayed in the top-left.
|
||||
getvvcol(wp, &wp->w_cursor, &vcol, NULL, NULL);
|
||||
if (wp->w_skipcol + 3 >= vcol) {
|
||||
check_topline = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Check if there are more filler lines than allowed.
|
||||
@ -1499,6 +1508,7 @@ void scroll_cursor_top(int min_scroll, int always)
|
||||
linenr_T top; // just above displayed lines
|
||||
linenr_T bot; // just below displayed lines
|
||||
linenr_T old_topline = curwin->w_topline;
|
||||
int old_skipcol = curwin->w_skipcol;
|
||||
linenr_T old_topfill = curwin->w_topfill;
|
||||
linenr_T new_topline;
|
||||
int off = (int)get_scrolloff_value(curwin);
|
||||
@ -1588,7 +1598,13 @@ void scroll_cursor_top(int min_scroll, int always)
|
||||
}
|
||||
}
|
||||
check_topfill(curwin, false);
|
||||
// TODO(vim): if the line doesn't fit may optimize w_skipcol
|
||||
if (curwin->w_topline == curwin->w_cursor.lnum) {
|
||||
curwin->w_skipcol = 0;
|
||||
redraw_later(curwin, UPD_NOT_VALID);
|
||||
}
|
||||
if (curwin->w_topline != old_topline
|
||||
|| curwin->w_skipcol != old_skipcol
|
||||
|| curwin->w_topfill != old_topfill) {
|
||||
curwin->w_valid &=
|
||||
~(VALID_WROW|VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP);
|
||||
|
@ -307,7 +307,7 @@ describe('smoothscroll', function()
|
||||
screen:try_resize(40, 8)
|
||||
exec([[
|
||||
call setline(1, ['Line' .. (' with some text'->repeat(7))]->repeat(7))
|
||||
set smoothscroll scrolloff=0
|
||||
set smoothscroll scrolloff=0 display=
|
||||
:3
|
||||
]])
|
||||
screen:expect([[
|
||||
@ -322,9 +322,22 @@ describe('smoothscroll', function()
|
||||
]])
|
||||
feed('j')
|
||||
screen:expect_unchanged()
|
||||
-- moving cursor down - whole bottom line shows
|
||||
feed('<C-E>j')
|
||||
screen:expect_unchanged()
|
||||
feed('G')
|
||||
screen:expect_unchanged()
|
||||
-- moving cursor up - whole top line shows
|
||||
feed('2k')
|
||||
screen:expect([[
|
||||
^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 |
|
||||
@ |
|
||||
|
|
||||
]])
|
||||
end)
|
||||
end)
|
||||
|
@ -198,6 +198,7 @@ func Test_smoothscroll_wrap_scrolloff_zero()
|
||||
|
||||
call VerifyScreenDump(buf, 'Test_smooth_wrap_1', {})
|
||||
|
||||
" moving cursor down - whole bottom line shows
|
||||
call term_sendkeys(buf, "j")
|
||||
call VerifyScreenDump(buf, 'Test_smooth_wrap_2', {})
|
||||
|
||||
@ -207,6 +208,10 @@ func Test_smoothscroll_wrap_scrolloff_zero()
|
||||
call term_sendkeys(buf, "G")
|
||||
call VerifyScreenDump(buf, 'Test_smooth_wrap_4', {})
|
||||
|
||||
" moving cursor up - whole top line shows
|
||||
call term_sendkeys(buf, "2k")
|
||||
call VerifyScreenDump(buf, 'Test_smooth_wrap_5', {})
|
||||
|
||||
call StopVimInTerminal(buf)
|
||||
endfunc
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user