From a2f3855291a59254346545f9699084fe4fece31f Mon Sep 17 00:00:00 2001 From: Luuk van Baal Date: Thu, 27 Apr 2023 17:51:47 +0200 Subject: vim-patch:9.0.0893: 'smoothscroll' cursor calculations wrong when 'number' is set Problem: 'smoothscroll' cursor calculations wrong when 'number' is set. Solution: Correct the code that computes the width. (closes vim/vim#11492) https://github.com/vim/vim/commit/01ee52bab6041450095c53f9469b1b266a7e3d4d Co-authored-by: Yee Cheng Chin --- src/nvim/move.c | 9 ++-- test/functional/legacy/scroll_opt_spec.lua | 4 +- test/old/testdir/test_scroll_opt.vim | 66 ++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 6 deletions(-) diff --git a/src/nvim/move.c b/src/nvim/move.c index cc8497f544..8113331c62 100644 --- a/src/nvim/move.c +++ b/src/nvim/move.c @@ -815,13 +815,14 @@ void curs_columns(win_T *wp, int may_scroll) if (wp->w_cursor.lnum == wp->w_topline && wp->w_skipcol > 0 && wp->w_wcol >= wp->w_skipcol) { - // w_skipcol excludes win_col_off(). Include it here, since w_wcol - // counts actual screen columns. + // Deduct by multiples of width2. This allows the long line wrapping + // formula below to correctly calculate the w_wcol value when wrapping. if (wp->w_skipcol <= width1) { - wp->w_wcol -= wp->w_width; + wp->w_wcol -= width2; } else { - wp->w_wcol -= wp->w_width * (((wp->w_skipcol - width1) / width2) + 1); + wp->w_wcol -= width2 * (((wp->w_skipcol - width1) / width2) + 1); } + did_sub_skipcol = true; } diff --git a/test/functional/legacy/scroll_opt_spec.lua b/test/functional/legacy/scroll_opt_spec.lua index 42d8f31d3c..8f0286771a 100644 --- a/test/functional/legacy/scroll_opt_spec.lua +++ b/test/functional/legacy/scroll_opt_spec.lua @@ -279,8 +279,8 @@ describe('smoothscroll', function() ]]) exec('call DoRel()') screen:expect([[ - 2<<" + + " Move down another line to avoid blocking the <<< display + call s:check_col_calc(1, 2, 41) + exe "normal \" + call s:check_col_calc(1, 3, 41) + normal ggg$ + exe "normal \" + + " Move down only 1 line when we are out of the range of the <<< display + call s:check_col_calc(20, 1, 40) + exe "normal \" + call s:check_col_calc(20, 2, 40) + normal gg + + " Test number, where we have indented lines + setl number + call s:check_col_calc(5, 1, 1) + exe "normal \" + call s:check_col_calc(5, 2, 33) + exe "normal \" + call s:check_col_calc(5, 3, 33) + normal ggg$ + exe "normal \" + call s:check_col_calc(20, 1, 32) + exe "normal \" + call s:check_col_calc(20, 2, 32) + normal gg + + " Test number + showbreak, so test that the additional indentation works + setl number showbreak=+++ + call s:check_col_calc(5, 1, 1) + exe "normal \" + call s:check_col_calc(8, 2, 30) + exe "normal \" + call s:check_col_calc(8, 3, 30) + normal gg + + " Test number + cpo+=n mode, where wrapped lines aren't indented + setl number cpo+=n showbreak= + call s:check_col_calc(5, 1, 1) + exe "normal \" + call s:check_col_calc(1, 2, 37) + exe "normal \" + call s:check_col_calc(1, 3, 37) + normal gg + + bwipeout! +endfunc + " vim: shiftwidth=2 sts=2 expandtab -- cgit