diff options
author | Luuk van Baal <luukvbaal@gmail.com> | 2023-04-26 23:23:50 +0200 |
---|---|---|
committer | Luuk van Baal <luukvbaal@gmail.com> | 2023-05-02 13:11:47 +0200 |
commit | e8dfff5f288f5fcf4a11d62e973080600f05c980 (patch) | |
tree | 3167cc610a5a97fee527577242008d73e7ed8e22 | |
parent | 9189c2d16260824db3f1a9633c17245c474baa9a (diff) | |
download | rneovim-e8dfff5f288f5fcf4a11d62e973080600f05c980.tar.gz rneovim-e8dfff5f288f5fcf4a11d62e973080600f05c980.tar.bz2 rneovim-e8dfff5f288f5fcf4a11d62e973080600f05c980.zip |
vim-patch:9.0.0745: wrong cursor position when using "gj" and "gk" in a long line
Problem: Wrong cursor position when using "gj" and "gk" in a long line.
Solution: Adjust computations for the cursor position and skipcol. Re-enable
tests that pass now, disable failing breakindent test.
https://github.com/vim/vim/commit/4b6172e108fe06be47c09f8690dc54608be3ee80
Co-authored-by: Bram Moolenaar <Bram@vim.org>
-rw-r--r-- | src/nvim/move.c | 12 | ||||
-rw-r--r-- | test/old/testdir/test_breakindent.vim | 3 | ||||
-rw-r--r-- | test/old/testdir/test_normal.vim | 42 |
3 files changed, 47 insertions, 10 deletions
diff --git a/src/nvim/move.c b/src/nvim/move.c index b2cf1ebc03..0cebcbdfdf 100644 --- a/src/nvim/move.c +++ b/src/nvim/move.c @@ -752,6 +752,7 @@ void curs_columns(win_T *wp, int may_scroll) colnr_T prev_skipcol; long so = get_scrolloff_value(wp); long siso = get_sidescrolloff_value(wp); + bool did_sub_skipcol = false; // First make sure that w_topline is valid (after moving the cursor). update_topline(wp); @@ -798,6 +799,7 @@ void curs_columns(win_T *wp, int may_scroll) if (wp->w_cursor.lnum == wp->w_topline && wp->w_wcol >= wp->w_skipcol) { wp->w_wcol -= wp->w_skipcol; + did_sub_skipcol = true; } // long line wrapping, adjust wp->w_wrow @@ -912,7 +914,7 @@ void curs_columns(win_T *wp, int may_scroll) extra += 2; } - if (extra == 3 || plines <= so * 2) { + if (extra == 3 || wp->w_height <= so * 2) { // not enough room for 'scrolloff', put cursor in the middle n = wp->w_virtcol / width; if (n > wp->w_height_inner / 2) { @@ -943,11 +945,17 @@ void curs_columns(win_T *wp, int may_scroll) endcol -= width; } if (endcol > wp->w_skipcol) { - wp->w_wrow -= (endcol - wp->w_skipcol) / width; wp->w_skipcol = endcol; } } + // adjust w_wrow for the changed w_skipcol + if (did_sub_skipcol) { + wp->w_wrow -= (wp->w_skipcol - prev_skipcol) / width; + } else { + wp->w_wrow -= wp->w_skipcol / width; + } + if (wp->w_wrow >= wp->w_height_inner) { // small window, make sure cursor is in it extra = wp->w_wrow - wp->w_height_inner + 1; diff --git a/test/old/testdir/test_breakindent.vim b/test/old/testdir/test_breakindent.vim index 76634a5ae5..2317cb8568 100644 --- a/test/old/testdir/test_breakindent.vim +++ b/test/old/testdir/test_breakindent.vim @@ -751,7 +751,8 @@ func Test_breakindent20_cpo_n_nextpage() \ " klmnopqrstabcd", \ " efghijklmnopqr", \ ] - call s:compare_lines(expect, lines) + " FIXME: this currently fails + " call s:compare_lines(expect, lines) call s:close_windows('set breakindent& briopt& cpo& number&') endfunc diff --git a/test/old/testdir/test_normal.vim b/test/old/testdir/test_normal.vim index 295c1b3d6a..600e58848b 100644 --- a/test/old/testdir/test_normal.vim +++ b/test/old/testdir/test_normal.vim @@ -3738,17 +3738,45 @@ endfunc " Test for 'scrolloff' with a long line that doesn't fit in the screen func Test_normal_scroloff() 10new - 80vnew - call setline(1, repeat('a', 1000)) + 60vnew + call setline(1, ' 1 ' .. repeat('a', 57) + \ .. ' 2 ' .. repeat('b', 57) + \ .. ' 3 ' .. repeat('c', 57) + \ .. ' 4 ' .. repeat('d', 57) + \ .. ' 5 ' .. repeat('e', 57) + \ .. ' 6 ' .. repeat('f', 57) + \ .. ' 7 ' .. repeat('g', 57) + \ .. ' 8 ' .. repeat('h', 57) + \ .. ' 9 ' .. repeat('i', 57) + \ .. '10 ' .. repeat('j', 57) + \ .. '11 ' .. repeat('k', 57) + \ .. '12 ' .. repeat('l', 57) + \ .. '13 ' .. repeat('m', 57) + \ .. '14 ' .. repeat('n', 57) + \ .. '15 ' .. repeat('o', 57) + \ .. '16 ' .. repeat('p', 57) + \ .. '17 ' .. repeat('q', 57) + \ .. '18 ' .. repeat('r', 57) + \ .. '19 ' .. repeat('s', 57) + \ .. '20 ' .. repeat('t', 57) + \ .. '21 ' .. repeat('u', 57) + \ .. '22 ' .. repeat('v', 57) + \ .. '23 ' .. repeat('w', 57) + \ .. '24 ' .. repeat('x', 57) + \ .. '25 ' .. repeat('y', 57) + \ .. '26 ' .. repeat('z', 57) + \ ) set scrolloff=10 normal gg10gj -" FIXME: currently get 10 -" call assert_equal(8, winline()) + call assert_equal(6, winline()) normal 10gj -" FIXME: currently get 9 -" call assert_equal(10, winline()) + call assert_equal(6, winline()) normal 10gk - call assert_equal(3, winline()) + call assert_equal(6, winline()) + normal 0 + call assert_equal(1, winline()) + normal $ + call assert_equal(10, winline()) set scrolloff& close! endfunc |