mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-patch:9.0.1525: 'smoothscroll' does not always work properly (#23544)
Problem: 'smoothscroll' does not always work properly.
Solution: Do not reset w_skipcol after it was intentionally set. (Luuk van
Baal, closes vim/vim#12360, closes vim/vim#12199, closes vim/vim#12323)
3ce8c38915
This commit is contained in:
parent
7ed4274f69
commit
44fc2a6d7e
@ -212,8 +212,6 @@ static void reset_skipcol(win_T *wp)
|
||||
// Update curwin->w_topline to move the cursor onto the screen.
|
||||
void update_topline(win_T *wp)
|
||||
{
|
||||
linenr_T old_topline;
|
||||
int old_topfill;
|
||||
bool check_botline = false;
|
||||
long *so_ptr = wp->w_p_so >= 0 ? &wp->w_p_so : &p_so;
|
||||
long save_so = *so_ptr;
|
||||
@ -243,8 +241,9 @@ void update_topline(win_T *wp)
|
||||
*so_ptr = mouse_dragging - 1;
|
||||
}
|
||||
|
||||
old_topline = wp->w_topline;
|
||||
old_topfill = wp->w_topfill;
|
||||
linenr_T old_topline = wp->w_topline;
|
||||
colnr_T old_skipcol = wp->w_skipcol;
|
||||
int old_topfill = wp->w_topfill;
|
||||
|
||||
// If the buffer is empty, always set topline to 1.
|
||||
if (buf_is_empty(curbuf)) { // special case - file is empty
|
||||
@ -408,7 +407,11 @@ void update_topline(win_T *wp)
|
||||
|| wp->w_topfill != old_topfill) {
|
||||
dollar_vcol = -1;
|
||||
redraw_later(wp, UPD_VALID);
|
||||
reset_skipcol(wp);
|
||||
|
||||
// Only reset w_skipcol if it was not just set to make cursor visible.
|
||||
if (wp->w_skipcol == old_skipcol) {
|
||||
reset_skipcol(wp);
|
||||
}
|
||||
|
||||
// May need to set w_skipcol when cursor in w_topline.
|
||||
if (wp->w_cursor.lnum == wp->w_topline) {
|
||||
@ -2112,15 +2115,18 @@ void scroll_cursor_halfway(bool atend, bool prefer_above)
|
||||
boff.fill = 0;
|
||||
linenr_T topline = loff.lnum;
|
||||
colnr_T skipcol = 0;
|
||||
bool set_skipcol = false;
|
||||
|
||||
int half_height = 0;
|
||||
int want_height;
|
||||
bool smooth_scroll = false;
|
||||
if (curwin->w_p_sms && curwin->w_p_wrap) {
|
||||
// 'smoothscroll' and 'wrap' are set
|
||||
smooth_scroll = true;
|
||||
half_height = (curwin->w_height_inner - used) / 2;
|
||||
used = 0;
|
||||
if (atend) {
|
||||
want_height = (curwin->w_height_inner - used) / 2;
|
||||
used = 0;
|
||||
} else {
|
||||
want_height = curwin->w_height_inner;
|
||||
}
|
||||
}
|
||||
|
||||
int topfill = 0;
|
||||
@ -2131,19 +2137,17 @@ void scroll_cursor_halfway(bool atend, bool prefer_above)
|
||||
topline_back_winheight(curwin, &loff, false);
|
||||
if (loff.height == MAXCOL) {
|
||||
break;
|
||||
} else {
|
||||
used += loff.height;
|
||||
}
|
||||
if (used > half_height) {
|
||||
if (used - loff.height < half_height) {
|
||||
int plines_offset = used - half_height;
|
||||
loff.height -= plines_offset;
|
||||
used = half_height;
|
||||
|
||||
used += loff.height;
|
||||
if (!atend && boff.lnum < curbuf->b_ml.ml_line_count) {
|
||||
botline_forw(curwin, &boff);
|
||||
used += boff.height;
|
||||
}
|
||||
if (used > want_height) {
|
||||
if (used - loff.height < want_height) {
|
||||
topline = loff.lnum;
|
||||
topfill = loff.fill;
|
||||
skipcol = skipcol_from_plines(curwin, plines_offset);
|
||||
set_skipcol = true;
|
||||
skipcol = skipcol_from_plines(curwin, used - want_height);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -2208,9 +2212,9 @@ void scroll_cursor_halfway(bool atend, bool prefer_above)
|
||||
}
|
||||
|
||||
if (!hasFolding(topline, &curwin->w_topline, NULL)
|
||||
&& (curwin->w_topline != topline || set_skipcol || curwin->w_skipcol != 0)) {
|
||||
&& (curwin->w_topline != topline || skipcol != 0 || curwin->w_skipcol != 0)) {
|
||||
curwin->w_topline = topline;
|
||||
if (set_skipcol) {
|
||||
if (skipcol != 0) {
|
||||
curwin->w_skipcol = skipcol;
|
||||
redraw_later(curwin, UPD_NOT_VALID);
|
||||
} else {
|
||||
|
@ -548,11 +548,11 @@ describe('smoothscroll', function()
|
||||
exec('set scrolloff=0')
|
||||
feed('0j')
|
||||
screen:expect([[
|
||||
<<<of text with lots of text with lots o|
|
||||
<<<th lots of text with lots of text wit|
|
||||
h lots of text with lots of text with lo|
|
||||
ts of text with lots of text with lots o|
|
||||
f text with lots of text end |
|
||||
^four |
|
||||
~ |
|
||||
~ |
|
||||
|
|
||||
]])
|
||||
-- Test zt/zz/zb that they work properly when a long line is above it
|
||||
@ -696,7 +696,7 @@ describe('smoothscroll', function()
|
||||
end)
|
||||
|
||||
-- oldtest: Test_smoothscroll_ins_lines()
|
||||
it("this was unnecessarily inserting lines", function()
|
||||
it("does not unnecessarily insert lines", function()
|
||||
screen:try_resize(40, 6)
|
||||
exec([=[
|
||||
set wrap smoothscroll scrolloff=0 conceallevel=2 concealcursor=nc
|
||||
@ -719,6 +719,67 @@ describe('smoothscroll', function()
|
||||
]])
|
||||
end)
|
||||
|
||||
-- oldtest: Test_smoothscroll_cursormoved_line()
|
||||
it("does not place the cursor in the command line", function()
|
||||
screen:try_resize(40, 6)
|
||||
exec([=[
|
||||
set smoothscroll
|
||||
call setline(1, [
|
||||
\'',
|
||||
\'_'->repeat(&lines * &columns),
|
||||
\(('_')->repeat(&columns - 2) .. 'xxx')->repeat(2)
|
||||
\])
|
||||
autocmd CursorMoved * eval [line('w0'), line('w$')]
|
||||
call search('xxx')
|
||||
]=])
|
||||
screen:expect([[
|
||||
<<<_____________________________________|
|
||||
________________________________________|
|
||||
______________________________________^xx|
|
||||
x______________________________________x|
|
||||
xx |
|
||||
|
|
||||
]])
|
||||
end)
|
||||
|
||||
-- oldtest: Test_smoothscroll_eob()
|
||||
it("does not scroll halfway at end of buffer", function()
|
||||
screen:try_resize(40, 10)
|
||||
exec([[
|
||||
set smoothscroll
|
||||
call setline(1, ['']->repeat(100))
|
||||
norm G
|
||||
]])
|
||||
-- does not scroll halfway when scrolling to end of buffer
|
||||
screen:expect([[
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
^ |
|
||||
|
|
||||
]])
|
||||
exec("call setline(92, 'a'->repeat(100))")
|
||||
feed('<C-B>G')
|
||||
-- cursor is not placed below window
|
||||
screen:expect([[
|
||||
<<<aaaaaaaaaaaaaaaaa |
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
^ |
|
||||
|
|
||||
]])
|
||||
end)
|
||||
|
||||
it("works with virt_lines above and below", function()
|
||||
screen:try_resize(55, 7)
|
||||
exec([=[
|
||||
|
@ -638,4 +638,47 @@ func Test_smoothscroll_ins_lines()
|
||||
call StopVimInTerminal(buf)
|
||||
endfunc
|
||||
|
||||
" this placed the cursor in the command line
|
||||
func Test_smoothscroll_cursormoved_line()
|
||||
CheckScreendump
|
||||
|
||||
let lines =<< trim END
|
||||
set smoothscroll
|
||||
call setline(1, [
|
||||
\'',
|
||||
\'_'->repeat(&lines * &columns),
|
||||
\(('_')->repeat(&columns - 2) .. 'xxx')->repeat(2)
|
||||
\])
|
||||
autocmd CursorMoved * eval [line('w0'), line('w$')]
|
||||
call search('xxx')
|
||||
END
|
||||
call writefile(lines, 'XSmoothCursorMovedLine', 'D')
|
||||
let buf = RunVimInTerminal('-S XSmoothCursorMovedLine', #{rows: 6})
|
||||
|
||||
call VerifyScreenDump(buf, 'Test_smooth_cursormoved_line', {})
|
||||
|
||||
call StopVimInTerminal(buf)
|
||||
endfunc
|
||||
|
||||
func Test_smoothscroll_eob()
|
||||
CheckScreendump
|
||||
|
||||
let lines =<< trim END
|
||||
set smoothscroll
|
||||
call setline(1, ['']->repeat(100))
|
||||
norm G
|
||||
END
|
||||
call writefile(lines, 'XSmoothEob', 'D')
|
||||
let buf = RunVimInTerminal('-S XSmoothEob', #{rows: 10})
|
||||
|
||||
" does not scroll halfway when scrolling to end of buffer
|
||||
call VerifyScreenDump(buf, 'Test_smooth_eob_1', {})
|
||||
|
||||
" cursor is not placed below window
|
||||
call term_sendkeys(buf, ":call setline(92, 'a'->repeat(100))\<CR>\<C-B>G")
|
||||
call VerifyScreenDump(buf, 'Test_smooth_eob_2', {})
|
||||
|
||||
call StopVimInTerminal(buf)
|
||||
endfunc
|
||||
|
||||
" vim: shiftwidth=2 sts=2 expandtab
|
||||
|
Loading…
Reference in New Issue
Block a user