diff options
author | Luuk van Baal <luukvbaal@gmail.com> | 2023-04-26 22:15:25 +0200 |
---|---|---|
committer | Luuk van Baal <luukvbaal@gmail.com> | 2023-05-02 13:11:47 +0200 |
commit | 36c98b47a3526dc61d149f951f8b8e3a677c26eb (patch) | |
tree | 45487f425ea6f65497a7ba434161f63bf634d49b /src/nvim/move.c | |
parent | f3de7f44685c8ec99c1f5c7a624a668044c5aa19 (diff) | |
download | rneovim-36c98b47a3526dc61d149f951f8b8e3a677c26eb.tar.gz rneovim-36c98b47a3526dc61d149f951f8b8e3a677c26eb.tar.bz2 rneovim-36c98b47a3526dc61d149f951f8b8e3a677c26eb.zip |
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.
https://github.com/vim/vim/commit/118c235112854f34182d968613d7fe98be3b290b
Co-authored-by: Bram Moolenaar <Bram@vim.org>
Diffstat (limited to 'src/nvim/move.c')
-rw-r--r-- | src/nvim/move.c | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/src/nvim/move.c b/src/nvim/move.c index 144384c294..e7f5959dbb 100644 --- a/src/nvim/move.c +++ b/src/nvim/move.c @@ -1210,20 +1210,24 @@ bool scrolldown(long line_count, int byfold) } 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 validate_virtcol(); - int col = curwin->w_virtcol - curwin->w_skipcol; + long col = curwin->w_virtcol - curwin->w_skipcol + scrolloff_cols; int row = 0; if (col >= width1) { col -= width1; - ++row; + row++; } if (col > width2) { - row += col / width2; + row += (int)col / width2; col = col % width2; } 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; @@ -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) { - // 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(); - if (curwin->w_virtcol < curwin->w_skipcol + 3) { - int width1 = curwin->w_width - curwin_col_off(); - int width2 = width1 + curwin_col_off2(); + if (curwin->w_virtcol < curwin->w_skipcol + 3 + scrolloff_cols) { colnr_T col = curwin->w_virtcol; if (col < width1) { col += width1; } - while (col < curwin->w_skipcol + 3) { + while (col < curwin->w_skipcol + 3 + scrolloff_cols) { col += width2; } - coladvance(col); + curwin->w_curswant = col; + coladvance(curwin->w_curswant); } } |