mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-patch:9.0.1664: divide by zero when scrolling with 'smoothscroll' set
Problem: Divide by zero when scrolling with 'smoothscroll' set.
Solution: Avoid using a negative width. (closes vim/vim#12540, closes vim/vim#12528)
8154e642aa
Co-authored-by: fullwaywang <fullwaywang@tencent.com>
This commit is contained in:
parent
0ca2d11c1f
commit
3b6fb3fefd
@ -1954,17 +1954,19 @@ void scroll_cursor_bot(int min_scroll, int set_topbot)
|
|||||||
int top_plines = plines_win_nofill(curwin, curwin->w_topline, false);
|
int top_plines = plines_win_nofill(curwin, curwin->w_topline, false);
|
||||||
int skip_lines = 0;
|
int skip_lines = 0;
|
||||||
int width1 = curwin->w_width_inner - curwin_col_off();
|
int width1 = curwin->w_width_inner - curwin_col_off();
|
||||||
int width2 = width1 + curwin_col_off2();
|
if (width1 > 0) {
|
||||||
// similar formula is used in curs_columns()
|
int width2 = width1 + curwin_col_off2();
|
||||||
if (curwin->w_skipcol > width1) {
|
// similar formula is used in curs_columns()
|
||||||
skip_lines += (curwin->w_skipcol - width1) / width2 + 1;
|
if (curwin->w_skipcol > width1) {
|
||||||
} else if (curwin->w_skipcol > 0) {
|
skip_lines += (curwin->w_skipcol - width1) / width2 + 1;
|
||||||
skip_lines = 1;
|
} else if (curwin->w_skipcol > 0) {
|
||||||
}
|
skip_lines = 1;
|
||||||
|
}
|
||||||
|
|
||||||
top_plines -= skip_lines;
|
top_plines -= skip_lines;
|
||||||
if (top_plines > curwin->w_height_inner) {
|
if (top_plines > curwin->w_height_inner) {
|
||||||
scrolled += (top_plines - curwin->w_height_inner);
|
scrolled += (top_plines - curwin->w_height_inner);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -939,6 +939,48 @@ describe('smoothscroll', function()
|
|||||||
]])
|
]])
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
-- oldtest: Test_smoothscroll_zero_width_scroll_cursor_bot()
|
||||||
|
it('does not divide by zero in zero-width window', function()
|
||||||
|
screen:try_resize(12, 19)
|
||||||
|
screen:set_default_attr_ids({
|
||||||
|
[1] = {foreground = Screen.colors.Brown}; -- LineNr
|
||||||
|
[2] = {bold = true, reverse = true}; -- StatusLine
|
||||||
|
[3] = {reverse = true}; -- StatusLineNC
|
||||||
|
})
|
||||||
|
exec([[
|
||||||
|
silent normal yy
|
||||||
|
silent normal 19p
|
||||||
|
winsize 0 19
|
||||||
|
vsplit
|
||||||
|
vertical resize 0
|
||||||
|
set foldcolumn=1
|
||||||
|
set number
|
||||||
|
set smoothscroll
|
||||||
|
silent normal 20G
|
||||||
|
]])
|
||||||
|
screen:expect([[
|
||||||
|
{1: }│ |
|
||||||
|
{1: }│ |
|
||||||
|
{1: }│ |
|
||||||
|
{1: }│ |
|
||||||
|
{1: }│ |
|
||||||
|
{1: }│ |
|
||||||
|
{1: }│ |
|
||||||
|
{1: }│ |
|
||||||
|
{1: }│ |
|
||||||
|
{1: }│ |
|
||||||
|
{1: }│ |
|
||||||
|
{1: }│ |
|
||||||
|
{1: }│ |
|
||||||
|
{1: }│ |
|
||||||
|
{1: }│ |
|
||||||
|
{1: }│ |
|
||||||
|
{1:^ }│ |
|
||||||
|
{2:< }{3:<ame] [+] }|
|
||||||
|
|
|
||||||
|
]])
|
||||||
|
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([=[
|
||||||
|
@ -836,4 +836,28 @@ func Test_smoothscroll_multi_skipcol()
|
|||||||
call StopVimInTerminal(buf)
|
call StopVimInTerminal(buf)
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
" this was dividing by zero bug in scroll_cursor_bot
|
||||||
|
func Test_smoothscroll_zero_width_scroll_cursor_bot()
|
||||||
|
CheckScreendump
|
||||||
|
|
||||||
|
let lines =<< trim END
|
||||||
|
silent normal yy
|
||||||
|
silent normal 19p
|
||||||
|
winsize 0 19
|
||||||
|
vsplit
|
||||||
|
vertical resize 0
|
||||||
|
set foldcolumn=1
|
||||||
|
set number
|
||||||
|
set smoothscroll
|
||||||
|
silent normal 20G
|
||||||
|
END
|
||||||
|
call writefile(lines, 'XSmoothScrollZeroBot', 'D')
|
||||||
|
let buf = RunVimInTerminal('-u NONE -S XSmoothScrollZeroBot', #{rows: 19, wait_for_ruler: 0})
|
||||||
|
call TermWait(buf, 1000)
|
||||||
|
|
||||||
|
call VerifyScreenDump(buf, 'Test_smoothscroll_zero_bot', {})
|
||||||
|
|
||||||
|
call StopVimInTerminal(buf)
|
||||||
|
endfunc
|
||||||
|
|
||||||
" vim: shiftwidth=2 sts=2 expandtab
|
" vim: shiftwidth=2 sts=2 expandtab
|
||||||
|
Loading…
Reference in New Issue
Block a user