]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0759: screenpos() may return invalid position v9.1.0759
authorChristian Brabandt <cb@256bit.org>
Sat, 5 Oct 2024 15:30:22 +0000 (17:30 +0200)
committerChristian Brabandt <cb@256bit.org>
Sat, 5 Oct 2024 15:30:22 +0000 (17:30 +0200)
Problem:  screenpos() may return invalid position
          after switching buffers (Greg Hurrell)
Solution: reset w_leftcol if wrapping has been set
          after copying wrap option

fixes: #15792
closes: #15803

Signed-off-by: Christian Brabandt <cb@256bit.org>
src/option.c
src/testdir/test_cursor_func.vim
src/version.c

index b38d77f5ac7b44285c83fb8d577afcd7ee11f51e..df0b647c09156be097741b4b35694954883cdb6d 100644 (file)
@@ -6737,6 +6737,11 @@ win_copy_options(win_T *wp_from, win_T *wp_to)
     void
 after_copy_winopt(win_T *wp)
 {
+    // Set w_leftcol or w_skipcol to zero.
+    if (wp->w_p_wrap)
+       wp->w_leftcol = 0;
+    else
+       wp->w_skipcol = 0;
 #ifdef FEAT_LINEBREAK
     briopt_check(wp);
 #endif
index 2bdda869e617490897f2ae4deaa7c683127ebd6b..8766f97d9dc1781316072d7d9003262ba05fc01f 100644 (file)
@@ -279,6 +279,21 @@ func Test_screenpos_number()
   bwipe!
 endfunc
 
+func Test_screenpos_edit_newfile()
+  new
+  20vsp
+  setl nowrap
+  call setline(1, 'abcdefghijklmnopqrstuvwxyz')
+  call cursor(1, 10)
+  norm! 5zl
+  call assert_equal(#{col: 5, row: 1, endcol: 5, curscol: 5}, screenpos(win_getid(), 1, 10))
+  enew!
+  call assert_equal(1, &l:wrap)
+  call assert_equal(#{col: 1, row: 1, endcol: 1, curscol: 1}, screenpos(win_getid(), 1, 1))
+
+  bwipe!
+endfunc
+
 " Save the visual start character position
 func SaveVisualStartCharPos()
   call add(g:VisualStartPos, getcharpos('v'))
index 047db755e1891966def3b68a8cb1326f630c8a64..63a6bc08792d0c3f1db8fccc0295b3788cbb57bd 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    759,
 /**/
     758,
 /**/