From e8dfff5f288f5fcf4a11d62e973080600f05c980 Mon Sep 17 00:00:00 2001 From: Luuk van Baal Date: Wed, 26 Apr 2023 23:23:50 +0200 Subject: 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 --- src/nvim/move.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/nvim') 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; -- cgit