mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 11:28:22 +00:00
vim-patch:9.0.0646: with 'smoothscroll' CTRL-E is wrong when 'foldmethod' set
Problem: with 'smoothscroll' set CTRL-E does not work properly when
'foldmethod' is set to "indent". (Yee Cheng Chin)
Solution: Merge the code for scroling with folds and 'smoothscroll'.
(closes vim/vim#11262)
6b2d4ff714
Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
@@ -707,8 +707,8 @@ int curwin_col_off(void)
|
||||
}
|
||||
|
||||
// Return the difference in column offset for the second screen line of a
|
||||
// wrapped line. It's 8 if 'number' or 'relativenumber' is on and 'n' is in
|
||||
// 'cpoptions'.
|
||||
// wrapped line. It's positive if 'number' or 'relativenumber' is on and 'n'
|
||||
// is in 'cpoptions'.
|
||||
int win_col_off2(win_T *wp)
|
||||
{
|
||||
if ((wp->w_p_nu || wp->w_p_rnu) && vim_strchr(p_cpo, CPO_NUMCOL) != NULL) {
|
||||
@@ -1097,7 +1097,7 @@ bool scrolldown(long line_count, int byfold)
|
||||
|
||||
if (curwin->w_p_wrap && curwin->w_p_sms) {
|
||||
width1 = curwin->w_width - curwin_col_off();
|
||||
width2 = width1 - curwin_col_off2();
|
||||
width2 = width1 + curwin_col_off2();
|
||||
}
|
||||
|
||||
// Make sure w_topline is at the first of a sequence of folded lines.
|
||||
@@ -1209,55 +1209,66 @@ bool scrollup(long line_count, int byfold)
|
||||
{
|
||||
linenr_T topline = curwin->w_topline;
|
||||
linenr_T botline = curwin->w_botline;
|
||||
int do_smoothscroll = curwin->w_p_wrap && curwin->w_p_sms;
|
||||
|
||||
if ((byfold && hasAnyFolding(curwin))
|
||||
|| win_may_fill(curwin)) {
|
||||
// count each sequence of folded lines as one logical line
|
||||
linenr_T lnum = curwin->w_topline;
|
||||
while (line_count--) {
|
||||
if (do_smoothscroll || (byfold && hasAnyFolding(curwin)) || win_may_fill(curwin)) {
|
||||
int width1 = curwin->w_width - curwin_col_off();
|
||||
int width2 = width1 + curwin_col_off2();
|
||||
int size = 0;
|
||||
linenr_T prev_topline = curwin->w_topline;
|
||||
|
||||
if (do_smoothscroll) {
|
||||
size = (int)win_linetabsize(curwin, curwin->w_topline,
|
||||
ml_get(curwin->w_topline), (colnr_T)MAXCOL);
|
||||
}
|
||||
|
||||
// diff mode: first consume "topfill"
|
||||
// 'smoothscroll': increase "w_skipcol" until it goes over the end of
|
||||
// the line, then advance to the next line.
|
||||
// folding: count each sequence of folded lines as one logical line.
|
||||
for (long todo = line_count; todo > 0; todo--) {
|
||||
if (curwin->w_topfill > 0) {
|
||||
curwin->w_topfill--;
|
||||
} else {
|
||||
linenr_T lnum = curwin->w_topline;
|
||||
if (byfold) {
|
||||
// for a closed fold: go to the last line in the fold
|
||||
(void)hasFolding(lnum, NULL, &lnum);
|
||||
}
|
||||
if (lnum == curwin->w_topline && curwin->w_p_wrap && curwin->w_p_sms) {
|
||||
// 'smoothscroll': increase "w_skipcol" until it goes over
|
||||
// the end of the line, then advance to the next line.
|
||||
int add = curwin->w_skipcol > 0 ? width2 : width1;
|
||||
curwin->w_skipcol += add;
|
||||
if (curwin->w_skipcol >= size) {
|
||||
if (lnum == curbuf->b_ml.ml_line_count) {
|
||||
// at the last screen line, can't scroll further
|
||||
curwin->w_skipcol -= add;
|
||||
break;
|
||||
}
|
||||
lnum++;
|
||||
}
|
||||
} else {
|
||||
if (lnum >= curbuf->b_ml.ml_line_count) {
|
||||
break;
|
||||
}
|
||||
lnum++;
|
||||
curwin->w_topfill = win_get_fill(curwin, lnum);
|
||||
}
|
||||
}
|
||||
|
||||
if (lnum > curwin->w_topline) {
|
||||
// approximate w_botline
|
||||
curwin->w_botline += lnum - curwin->w_topline;
|
||||
curwin->w_topline = lnum;
|
||||
} else if (curwin->w_p_wrap && curwin->w_p_sms) {
|
||||
int off1 = curwin_col_off();
|
||||
int off2 = off1 + curwin_col_off2();
|
||||
int add;
|
||||
int size = (int)win_linetabsize(curwin, curwin->w_topline,
|
||||
ml_get(curwin->w_topline), (colnr_T)MAXCOL);
|
||||
linenr_T prev_topline = curwin->w_topline;
|
||||
|
||||
// 'smoothscroll': increase "w_skipcol" until it goes over the end of
|
||||
// the line, then advance to the next line.
|
||||
for (long todo = line_count; todo > 0; todo--) {
|
||||
add = curwin->w_width - (curwin->w_skipcol > 0 ? off2 : off1);
|
||||
curwin->w_skipcol += add;
|
||||
if (curwin->w_skipcol >= size) {
|
||||
if (curwin->w_topline == curbuf->b_ml.ml_line_count) {
|
||||
curwin->w_skipcol -= add;
|
||||
break;
|
||||
}
|
||||
curwin->w_topline++;
|
||||
curwin->w_botline++; // approximate w_botline
|
||||
curwin->w_topfill = win_get_fill(curwin, lnum);
|
||||
curwin->w_skipcol = 0;
|
||||
if (todo > 1) {
|
||||
if (todo > 1 && do_smoothscroll) {
|
||||
size = (int)win_linetabsize(curwin, curwin->w_topline,
|
||||
ml_get(curwin->w_topline), (colnr_T)MAXCOL);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (curwin->w_topline == prev_topline) {
|
||||
// need to redraw even though w_topline didn't change
|
||||
redraw_later(curwin, UPD_NOT_VALID);
|
||||
|
@@ -31,23 +31,9 @@ describe('smoothscroll', function()
|
||||
it('works with <C-E> and <C-E>', function()
|
||||
exec([[
|
||||
call setline(1, [ 'line one', 'word '->repeat(20), 'line three', 'long word '->repeat(7), 'line', 'line', 'line', ])
|
||||
set smoothscroll
|
||||
set smoothscroll scrolloff=5
|
||||
:5
|
||||
]])
|
||||
local s0 = [[
|
||||
line one |
|
||||
word word word word word word word word |
|
||||
word word word word word word word word |
|
||||
word word word word |
|
||||
line three |
|
||||
long word long word long word long word |
|
||||
long word long word long word |
|
||||
^line |
|
||||
line |
|
||||
line |
|
||||
~ |
|
||||
|
|
||||
]]
|
||||
local s1 = [[
|
||||
word word word word word word word word |
|
||||
word word word word word word word word |
|
||||
@@ -94,13 +80,69 @@ describe('smoothscroll', function()
|
||||
line three |
|
||||
long word long word long word long word |
|
||||
long word long word long word |
|
||||
line |
|
||||
line |
|
||||
^line |
|
||||
~ |
|
||||
~ |
|
||||
~ |
|
||||
~ |
|
||||
~ |
|
||||
|
|
||||
]]
|
||||
local s5 = [[
|
||||
word word word word |
|
||||
line three |
|
||||
long word long word long word long word |
|
||||
long word long word long word |
|
||||
line |
|
||||
line |
|
||||
^line |
|
||||
~ |
|
||||
~ |
|
||||
~ |
|
||||
~ |
|
||||
|
|
||||
]]
|
||||
local s6 = [[
|
||||
word word word word word word word word |
|
||||
word word word word |
|
||||
line three |
|
||||
long word long word long word long word |
|
||||
long word long word long word |
|
||||
line |
|
||||
line |
|
||||
^line |
|
||||
~ |
|
||||
~ |
|
||||
~ |
|
||||
|
|
||||
]]
|
||||
local s7 = [[
|
||||
word word word word word word word word |
|
||||
word word word word word word word word |
|
||||
word word word word |
|
||||
line three |
|
||||
long word long word long word long word |
|
||||
long word long word long word |
|
||||
line |
|
||||
line |
|
||||
^line |
|
||||
~ |
|
||||
~ |
|
||||
|
|
||||
]]
|
||||
local s8 = [[
|
||||
line one |
|
||||
word word word word word word word word |
|
||||
word word word word word word word word |
|
||||
word word word word |
|
||||
line three |
|
||||
long word long word long word long word |
|
||||
long word long word long word |
|
||||
line |
|
||||
line |
|
||||
^line |
|
||||
~ |
|
||||
|
|
||||
]]
|
||||
@@ -113,12 +155,22 @@ describe('smoothscroll', function()
|
||||
feed('<C-E>')
|
||||
screen:expect(s4)
|
||||
feed('<C-Y>')
|
||||
screen:expect(s3)
|
||||
screen:expect(s5)
|
||||
feed('<C-Y>')
|
||||
screen:expect(s2)
|
||||
screen:expect(s6)
|
||||
feed('<C-Y>')
|
||||
screen:expect(s7)
|
||||
feed('<C-Y>')
|
||||
screen:expect(s8)
|
||||
exec('set foldmethod=indent')
|
||||
-- move the cursor so we can reuse the same dumps
|
||||
feed('5G<C-E>')
|
||||
screen:expect(s1)
|
||||
feed('<C-E>')
|
||||
screen:expect(s2)
|
||||
feed('7G<C-Y>')
|
||||
screen:expect(s7)
|
||||
feed('<C-Y>')
|
||||
screen:expect(s0)
|
||||
screen:expect(s8)
|
||||
end)
|
||||
end)
|
||||
|
@@ -105,6 +105,21 @@ func Test_smoothscroll_CtrlE_CtrlY()
|
||||
call term_sendkeys(buf, "\<C-Y>")
|
||||
call VerifyScreenDump(buf, 'Test_smoothscroll_8', {})
|
||||
|
||||
if has('folding')
|
||||
call term_sendkeys(buf, ":set foldmethod=indent\<CR>")
|
||||
" move the cursor so we can reuse the same dumps
|
||||
call term_sendkeys(buf, "5G")
|
||||
call term_sendkeys(buf, "\<C-E>")
|
||||
call VerifyScreenDump(buf, 'Test_smoothscroll_1', {})
|
||||
call term_sendkeys(buf, "\<C-E>")
|
||||
call VerifyScreenDump(buf, 'Test_smoothscroll_2', {})
|
||||
call term_sendkeys(buf, "7G")
|
||||
call term_sendkeys(buf, "\<C-Y>")
|
||||
call VerifyScreenDump(buf, 'Test_smoothscroll_7', {})
|
||||
call term_sendkeys(buf, "\<C-Y>")
|
||||
call VerifyScreenDump(buf, 'Test_smoothscroll_8', {})
|
||||
endif
|
||||
|
||||
call StopVimInTerminal(buf)
|
||||
endfunc
|
||||
|
||||
|
Reference in New Issue
Block a user