From 9e7f1fc2f159d58b2a4cd4b7060bead126fead49 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 16 Mar 2024 09:40:22 +0100 Subject: patch 9.1.0183: Wrong display or screenpos() result when toggling diff mode Problem: Wrong display or screenpos() result when toggling diff mode. Solution: Reset w_skipcol when disabling 'wrap'. Reset w_leftcol when enabling 'wrap' (zeertzjq). fixes: #14210 closes: #14211 Signed-off-by: zeertzjq Signed-off-by: Christian Brabandt --- src/diff.c | 8 ++++-- src/testdir/test_diffmode.vim | 67 +++++++++++++++++++++++++++++++++++++++++++ src/version.c | 2 ++ 3 files changed, 75 insertions(+), 2 deletions(-) diff --git a/src/diff.c b/src/diff.c index e1c8f58de6..c50670cdf5 100644 --- a/src/diff.c +++ b/src/diff.c @@ -1520,6 +1520,7 @@ diff_win_options( if (!wp->w_p_diff) wp->w_p_wrap_save = wp->w_p_wrap; wp->w_p_wrap = FALSE; + wp->w_skipcol = 0; } # ifdef FEAT_FOLDING if (!wp->w_p_diff) @@ -1583,8 +1584,11 @@ ex_diffoff(exarg_T *eap) wp->w_p_crb = wp->w_p_crb_save; if (!(diff_flags & DIFF_FOLLOWWRAP)) { - if (!wp->w_p_wrap) - wp->w_p_wrap = wp->w_p_wrap_save; + if (!wp->w_p_wrap && wp->w_p_wrap_save) + { + wp->w_p_wrap = TRUE; + wp->w_leftcol = 0; + } } #ifdef FEAT_FOLDING free_string_option(wp->w_p_fdm); diff --git a/src/testdir/test_diffmode.vim b/src/testdir/test_diffmode.vim index b44879f71e..7602bd374a 100644 --- a/src/testdir/test_diffmode.vim +++ b/src/testdir/test_diffmode.vim @@ -3,6 +3,7 @@ source shared.vim source screendump.vim source check.vim +source view_util.vim func Test_diff_fold_sync() enew! @@ -1953,4 +1954,70 @@ func Test_diffexpr_with_diff_func() call StopVimInTerminal(buf) endfunc +func Test_diff_toggle_wrap_skipcol_leftcol() + 61vnew + call setline(1, 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.') + 30vnew + call setline(1, 'ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.') + let win1 = win_getid() + setlocal smoothscroll + exe "normal! $\" + wincmd l + let win2 = win_getid() + setlocal smoothscroll + exe "normal! $\" + call assert_equal([ + \ '<<