mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-patch:9.0.0701: with 'smoothscroll' cursor position not adjusted in long line
Problem: With 'smoothscroll' the cursor position s not adjusted in a long
line.
Solution: Move the cursor further up or down in the line.
8cf3459878
Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
parent
2918720add
commit
f3de7f4468
@ -1208,6 +1208,24 @@ bool scrolldown(long line_count, int byfold)
|
|||||||
foldAdjustCursor();
|
foldAdjustCursor();
|
||||||
coladvance(curwin->w_curswant);
|
coladvance(curwin->w_curswant);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (curwin->w_cursor.lnum == curwin->w_topline && do_sms) {
|
||||||
|
// make sure the cursor is in the visible text
|
||||||
|
validate_virtcol();
|
||||||
|
int col = curwin->w_virtcol - curwin->w_skipcol;
|
||||||
|
int row = 0;
|
||||||
|
if (col >= width1) {
|
||||||
|
col -= width1;
|
||||||
|
++row;
|
||||||
|
}
|
||||||
|
if (col > width2) {
|
||||||
|
row += col / width2;
|
||||||
|
col = col % width2;
|
||||||
|
}
|
||||||
|
if (row >= curwin->w_height) {
|
||||||
|
coladvance(curwin->w_virtcol - (row - curwin->w_height + 1) * width2);
|
||||||
|
}
|
||||||
|
}
|
||||||
return moved;
|
return moved;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1245,7 +1263,7 @@ bool scrollup(long line_count, int byfold)
|
|||||||
// for a closed fold: go to the last line in the fold
|
// for a closed fold: go to the last line in the fold
|
||||||
(void)hasFolding(lnum, NULL, &lnum);
|
(void)hasFolding(lnum, NULL, &lnum);
|
||||||
}
|
}
|
||||||
if (lnum == curwin->w_topline && curwin->w_p_wrap && curwin->w_p_sms) {
|
if (lnum == curwin->w_topline && do_sms) {
|
||||||
// 'smoothscroll': increase "w_skipcol" until it goes over
|
// 'smoothscroll': increase "w_skipcol" until it goes over
|
||||||
// the end of the line, then advance to the next line.
|
// the end of the line, then advance to the next line.
|
||||||
int add = curwin->w_skipcol > 0 ? width2 : width1;
|
int add = curwin->w_skipcol > 0 ? width2 : width1;
|
||||||
@ -1310,6 +1328,24 @@ bool scrollup(long line_count, int byfold)
|
|||||||
coladvance(curwin->w_curswant);
|
coladvance(curwin->w_curswant);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
validate_virtcol();
|
||||||
|
if (curwin->w_virtcol < curwin->w_skipcol + 3) {
|
||||||
|
int width1 = curwin->w_width - curwin_col_off();
|
||||||
|
int width2 = width1 + curwin_col_off2();
|
||||||
|
colnr_T col = curwin->w_virtcol;
|
||||||
|
|
||||||
|
if (col < width1) {
|
||||||
|
col += width1;
|
||||||
|
}
|
||||||
|
while (col < curwin->w_skipcol + 3) {
|
||||||
|
col += width2;
|
||||||
|
}
|
||||||
|
coladvance(col);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool moved = topline != curwin->w_topline
|
bool moved = topline != curwin->w_topline
|
||||||
|| botline != curwin->w_botline;
|
|| botline != curwin->w_botline;
|
||||||
|
|
||||||
|
@ -340,4 +340,60 @@ describe('smoothscroll', function()
|
|||||||
|
|
|
|
||||||
]])
|
]])
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
-- oldtest: Test_smoothscroll_wrap_long_line()
|
||||||
|
it("adjusts the cursor position in a long line", function()
|
||||||
|
screen:try_resize(40, 6)
|
||||||
|
exec([[
|
||||||
|
call setline(1, ['one', 'two', 'Line' .. (' with lots of text'->repeat(30))])
|
||||||
|
set smoothscroll scrolloff=0
|
||||||
|
normal 3G10|zt
|
||||||
|
]])
|
||||||
|
-- scrolling up, cursor moves screen line down
|
||||||
|
screen:expect([[
|
||||||
|
Line with^ lots of text with lots of text|
|
||||||
|
with 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|
|
||||||
|
|
|
||||||
|
]])
|
||||||
|
feed('<C-E>')
|
||||||
|
screen:expect([[
|
||||||
|
<<<th lot^s 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|
|
||||||
|
|
|
||||||
|
]])
|
||||||
|
feed('5<C-E>')
|
||||||
|
screen:expect([[
|
||||||
|
<<< lots ^of text with lots of text with |
|
||||||
|
lots of text with lots of text with lots|
|
||||||
|
of text with lots of text with lots of |
|
||||||
|
text with lots of text with lots of text|
|
||||||
|
with lots of text with lots of text wit|
|
||||||
|
|
|
||||||
|
]])
|
||||||
|
-- scrolling down, cursor moves screen line up
|
||||||
|
feed('5<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 with lots of text with lots of te|
|
||||||
|
xt with l^ots of text with lots of text w|
|
||||||
|
|
|
||||||
|
]])
|
||||||
|
feed('<C-Y>')
|
||||||
|
screen:expect([[
|
||||||
|
Line with lots of text with lots of text|
|
||||||
|
with 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|
|
||||||
|
|
|
||||||
|
]])
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
@ -215,5 +215,33 @@ func Test_smoothscroll_wrap_scrolloff_zero()
|
|||||||
call StopVimInTerminal(buf)
|
call StopVimInTerminal(buf)
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_smoothscroll_wrap_long_line()
|
||||||
|
CheckScreendump
|
||||||
|
|
||||||
|
let lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
setline(1, ['one', 'two', 'Line' .. (' with lots of text'->repeat(30))])
|
||||||
|
set smoothscroll scrolloff=0
|
||||||
|
normal 3G10|zt
|
||||||
|
END
|
||||||
|
call writefile(lines, 'XSmoothWrap', 'D')
|
||||||
|
let buf = RunVimInTerminal('-S XSmoothWrap', #{rows: 6, cols: 40})
|
||||||
|
call VerifyScreenDump(buf, 'Test_smooth_long_1', {})
|
||||||
|
|
||||||
|
" scrolling up, cursor moves screen line down
|
||||||
|
call term_sendkeys(buf, "\<C-E>")
|
||||||
|
call VerifyScreenDump(buf, 'Test_smooth_long_2', {})
|
||||||
|
call term_sendkeys(buf, "5\<C-E>")
|
||||||
|
call VerifyScreenDump(buf, 'Test_smooth_long_3', {})
|
||||||
|
|
||||||
|
" scrolling down, cursor moves screen line up
|
||||||
|
call term_sendkeys(buf, "5\<C-Y>")
|
||||||
|
call VerifyScreenDump(buf, 'Test_smooth_long_4', {})
|
||||||
|
call term_sendkeys(buf, "\<C-Y>")
|
||||||
|
call VerifyScreenDump(buf, 'Test_smooth_long_5', {})
|
||||||
|
|
||||||
|
call StopVimInTerminal(buf)
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
|
||||||
" vim: shiftwidth=2 sts=2 expandtab
|
" vim: shiftwidth=2 sts=2 expandtab
|
||||||
|
Loading…
Reference in New Issue
Block a user