mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-patch:9.0.0707: with 'smoothscroll' cursor position not adjusted in long line
Problem: With 'smoothscroll' and 'scrolloff' non-zero the cursor position
is not properly adjusted in a long line.
Solution: Move the cursor further up or down in the line.
118c235112
Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
parent
f3de7f4468
commit
36c98b47a3
@ -1210,20 +1210,24 @@ bool scrolldown(long line_count, int byfold)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (curwin->w_cursor.lnum == curwin->w_topline && do_sms) {
|
if (curwin->w_cursor.lnum == curwin->w_topline && do_sms) {
|
||||||
|
long so = curwin->w_p_so >= 0 ? curwin->w_p_so : p_so;
|
||||||
|
long scrolloff_cols = so == 0 ? 0 : width1 + (so - 1) * width2;
|
||||||
|
|
||||||
// make sure the cursor is in the visible text
|
// make sure the cursor is in the visible text
|
||||||
validate_virtcol();
|
validate_virtcol();
|
||||||
int col = curwin->w_virtcol - curwin->w_skipcol;
|
long col = curwin->w_virtcol - curwin->w_skipcol + scrolloff_cols;
|
||||||
int row = 0;
|
int row = 0;
|
||||||
if (col >= width1) {
|
if (col >= width1) {
|
||||||
col -= width1;
|
col -= width1;
|
||||||
++row;
|
row++;
|
||||||
}
|
}
|
||||||
if (col > width2) {
|
if (col > width2) {
|
||||||
row += col / width2;
|
row += (int)col / width2;
|
||||||
col = col % width2;
|
col = col % width2;
|
||||||
}
|
}
|
||||||
if (row >= curwin->w_height) {
|
if (row >= curwin->w_height) {
|
||||||
coladvance(curwin->w_virtcol - (row - curwin->w_height + 1) * width2);
|
curwin->w_curswant = curwin->w_virtcol - (row - curwin->w_height + 1) * width2;
|
||||||
|
coladvance(curwin->w_curswant);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return moved;
|
return moved;
|
||||||
@ -1329,20 +1333,25 @@ bool scrollup(long line_count, int byfold)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (curwin->w_cursor.lnum == curwin->w_topline && do_sms && curwin->w_skipcol > 0) {
|
if (curwin->w_cursor.lnum == curwin->w_topline && do_sms && curwin->w_skipcol > 0) {
|
||||||
// make sure the cursor is in a visible part of the line
|
int width1 = curwin->w_width - curwin_col_off();
|
||||||
|
int width2 = width1 + curwin_col_off2();
|
||||||
|
long so = curwin->w_p_so >= 0 ? curwin->w_p_so : p_so;
|
||||||
|
long scrolloff_cols = so == 0 ? 0 : width1 + (so - 1) * width2;
|
||||||
|
|
||||||
|
// Make sure the cursor is in a visible part of the line, taking
|
||||||
|
// 'scrolloff' into account, but using screen lines.
|
||||||
validate_virtcol();
|
validate_virtcol();
|
||||||
if (curwin->w_virtcol < curwin->w_skipcol + 3) {
|
if (curwin->w_virtcol < curwin->w_skipcol + 3 + scrolloff_cols) {
|
||||||
int width1 = curwin->w_width - curwin_col_off();
|
|
||||||
int width2 = width1 + curwin_col_off2();
|
|
||||||
colnr_T col = curwin->w_virtcol;
|
colnr_T col = curwin->w_virtcol;
|
||||||
|
|
||||||
if (col < width1) {
|
if (col < width1) {
|
||||||
col += width1;
|
col += width1;
|
||||||
}
|
}
|
||||||
while (col < curwin->w_skipcol + 3) {
|
while (col < curwin->w_skipcol + 3 + scrolloff_cols) {
|
||||||
col += width2;
|
col += width2;
|
||||||
}
|
}
|
||||||
coladvance(col);
|
curwin->w_curswant = col;
|
||||||
|
coladvance(curwin->w_curswant);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -395,5 +395,47 @@ describe('smoothscroll', function()
|
|||||||
f text wi^th lots of text with lots of te|
|
f text wi^th lots of text with lots of te|
|
||||||
|
|
|
|
||||||
]])
|
]])
|
||||||
|
-- 'scrolloff' set to 1, scrolling up, cursor moves screen line down
|
||||||
|
exec('set scrolloff=1')
|
||||||
|
feed('10|<C-E>')
|
||||||
|
screen:expect([[
|
||||||
|
<<<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 with lots of te|
|
||||||
|
xt with lots of text with lots of text w|
|
||||||
|
|
|
||||||
|
]])
|
||||||
|
-- 'scrolloff' set to 1, scrolling down, cursor moves screen line up
|
||||||
|
feed('<C-E>gjgj<C-Y>')
|
||||||
|
screen:expect([[
|
||||||
|
<<<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 wi^th lots of text with lots of te|
|
||||||
|
xt with lots of text with lots of text w|
|
||||||
|
|
|
||||||
|
]])
|
||||||
|
-- 'scrolloff' set to 2, scrolling up, cursor moves screen line down
|
||||||
|
exec('set scrolloff=2')
|
||||||
|
feed('10|<C-E>')
|
||||||
|
screen:expect([[
|
||||||
|
<<<th lots of text with lots of text wit|
|
||||||
|
h lots of text with lots of text with lo|
|
||||||
|
ts of tex^t with lots of text with lots o|
|
||||||
|
f text with lots of text with lots of te|
|
||||||
|
xt with lots of text with lots of text w|
|
||||||
|
|
|
||||||
|
]])
|
||||||
|
-- 'scrolloff' set to 2, scrolling down, cursor moves screen line up
|
||||||
|
feed('<C-E>gjgj<C-Y>')
|
||||||
|
screen:expect([[
|
||||||
|
<<<of text with lots of text with lots o|
|
||||||
|
f text with lots of text with lots of te|
|
||||||
|
xt with l^ots of text with lots of text w|
|
||||||
|
ith lots of text with lots of text with |
|
||||||
|
lots of text with lots of text with lots|
|
||||||
|
|
|
||||||
|
]])
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
@ -240,6 +240,28 @@ func Test_smoothscroll_wrap_long_line()
|
|||||||
call term_sendkeys(buf, "\<C-Y>")
|
call term_sendkeys(buf, "\<C-Y>")
|
||||||
call VerifyScreenDump(buf, 'Test_smooth_long_5', {})
|
call VerifyScreenDump(buf, 'Test_smooth_long_5', {})
|
||||||
|
|
||||||
|
" 'scrolloff' set to 1, scrolling up, cursor moves screen line down
|
||||||
|
call term_sendkeys(buf, ":set scrolloff=1\<CR>")
|
||||||
|
call term_sendkeys(buf, "10|\<C-E>")
|
||||||
|
call VerifyScreenDump(buf, 'Test_smooth_long_6', {})
|
||||||
|
|
||||||
|
" 'scrolloff' set to 1, scrolling down, cursor moves screen line up
|
||||||
|
call term_sendkeys(buf, "\<C-E>")
|
||||||
|
call term_sendkeys(buf, "gjgj")
|
||||||
|
call term_sendkeys(buf, "\<C-Y>")
|
||||||
|
call VerifyScreenDump(buf, 'Test_smooth_long_7', {})
|
||||||
|
|
||||||
|
" 'scrolloff' set to 2, scrolling up, cursor moves screen line down
|
||||||
|
call term_sendkeys(buf, ":set scrolloff=2\<CR>")
|
||||||
|
call term_sendkeys(buf, "10|\<C-E>")
|
||||||
|
call VerifyScreenDump(buf, 'Test_smooth_long_8', {})
|
||||||
|
|
||||||
|
" 'scrolloff' set to 2, scrolling down, cursor moves screen line up
|
||||||
|
call term_sendkeys(buf, "\<C-E>")
|
||||||
|
call term_sendkeys(buf, "gj")
|
||||||
|
call term_sendkeys(buf, "\<C-Y>")
|
||||||
|
call VerifyScreenDump(buf, 'Test_smooth_long_9', {})
|
||||||
|
|
||||||
call StopVimInTerminal(buf)
|
call StopVimInTerminal(buf)
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user