Patch 8.2.4389
Problem:    screenpos() does not handle a position in a closed fold.
Solution:   Check if the position is inside a closed fold. (closes #9778)
Files:      src/move.c, src/testdir/test_cursor_func.vim


*** ../vim-8.2.4388/src/move.c  2022-01-24 16:15:11.214984160 +0000
--- src/move.c  2022-02-15 13:37:27.009136975 +0000
***************
*** 1236,1274 ****
  
      if (pos->lnum >= wp->w_topline && pos->lnum <= wp->w_botline)
      {
!       colnr_T off;
!       colnr_T col;
!       int     width;
  
!       row = plines_m_win(wp, wp->w_topline, pos->lnum - 1) + 1;
!       getvcol(wp, pos, &scol, &ccol, &ecol);
! 
!       // similar to what is done in validate_cursor_col()
!       col = scol;
!       off = win_col_off(wp);
!       col += off;
!       width = wp->w_width - off + win_col_off2(wp);
! 
!       // long line wrapping, adjust row
!       if (wp->w_p_wrap
!               && col >= (colnr_T)wp->w_width
!               && width > 0)
!       {
!           // use same formula as what is used in curs_columns()
!           rowoff = ((col - wp->w_width) / width + 1);
!           col -= rowoff * width;
!       }
!       col -= wp->w_leftcol;
!       if (col >= wp->w_width)
!           col = -1;
!       if (col >= 0 && row + rowoff <= wp->w_height)
        {
-           coloff = col - scol + wp->w_wincol + 1;
            row += W_WINROW(wp);
        }
        else
!           // character is left, right or below of the window
!           row = rowoff = scol = ccol = ecol = 0;
      }
      *rowp = row + rowoff;
      *scolp = scol + coloff;
--- 1236,1289 ----
  
      if (pos->lnum >= wp->w_topline && pos->lnum <= wp->w_botline)
      {
!       colnr_T     off;
!       colnr_T     col;
!       int         width;
!       linenr_T    lnum = pos->lnum;
! #ifdef FEAT_FOLDING
!       int         is_folded;
  
!       is_folded = hasFoldingWin(wp, lnum, &lnum, NULL, TRUE, NULL);
! #endif
!       row = plines_m_win(wp, wp->w_topline, lnum - 1) + 1;
! #ifdef FEAT_FOLDING
!       if (is_folded)
        {
            row += W_WINROW(wp);
+           coloff = wp->w_wincol + 1;
        }
        else
! #endif
!       {
!           getvcol(wp, pos, &scol, &ccol, &ecol);
! 
!           // similar to what is done in validate_cursor_col()
!           col = scol;
!           off = win_col_off(wp);
!           col += off;
!           width = wp->w_width - off + win_col_off2(wp);
! 
!           // long line wrapping, adjust row
!           if (wp->w_p_wrap
!                   && col >= (colnr_T)wp->w_width
!                   && width > 0)
!           {
!               // use same formula as what is used in curs_columns()
!               rowoff = ((col - wp->w_width) / width + 1);
!               col -= rowoff * width;
!           }
!           col -= wp->w_leftcol;
!           if (col >= wp->w_width)
!               col = -1;
!           if (col >= 0 && row + rowoff <= wp->w_height)
!           {
!               coloff = col - scol + wp->w_wincol + 1;
!               row += W_WINROW(wp);
!           }
!           else
!               // character is left, right or below of the window
!               row = rowoff = scol = ccol = ecol = 0;
!       }
      }
      *rowp = row + rowoff;
      *scolp = scol + coloff;
*** ../vim-8.2.4388/src/testdir/test_cursor_func.vim    2022-01-24 
16:15:11.214984160 +0000
--- src/testdir/test_cursor_func.vim    2022-02-15 13:36:16.357223054 +0000
***************
*** 1,5 ****
--- 1,7 ----
  " Tests for cursor() and other functions that get/set the cursor position
  
+ source check.vim
+ 
  func Test_wrong_arguments()
    call assert_fails('call cursor(1. 3)', 'E474:')
    call assert_fails('call cursor(test_null_list())', 'E474:')
***************
*** 133,144 ****
    bwipe!
    set display&
  
!   call assert_equal({'col': 1, 'row': 1, 'endcol': 1, 'curscol': 1}, 
screenpos(win_getid(), 1, 1))
    nmenu WinBar.TEST :
!   call assert_equal({'col': 1, 'row': 2, 'endcol': 1, 'curscol': 1}, 
screenpos(win_getid(), 1, 1))
    nunmenu WinBar.TEST
  endfunc
  
  func Test_screenpos_number()
    rightbelow new
    rightbelow 73vsplit
--- 135,161 ----
    bwipe!
    set display&
  
!   call assert_equal(#{col: 1, row: 1, endcol: 1, curscol: 1}, 
screenpos(win_getid(), 1, 1))
    nmenu WinBar.TEST :
!   call assert_equal(#{col: 1, row: 2, endcol: 1, curscol: 1}, 
screenpos(win_getid(), 1, 1))
    nunmenu WinBar.TEST
  endfunc
  
+ func Test_screenpos_fold()
+   CheckFeature folding
+ 
+   enew!
+   call setline(1, range(10))
+   3,5fold
+   redraw
+   call assert_equal(2, screenpos(1, 2, 1).row)
+   call assert_equal(#{col: 1, row: 3, endcol: 1, curscol: 1}, screenpos(1, 3, 
1))
+   call assert_equal(3, screenpos(1, 4, 1).row)
+   call assert_equal(3, screenpos(1, 5, 1).row)
+   call assert_equal(4, screenpos(1, 6, 1).row)
+   bwipe!
+ endfunc
+ 
  func Test_screenpos_number()
    rightbelow new
    rightbelow 73vsplit
*** ../vim-8.2.4388/src/version.c       2022-02-15 11:48:17.533999966 +0000
--- src/version.c       2022-02-15 13:21:23.878585629 +0000
***************
*** 752,753 ****
--- 752,755 ----
  {   /* Add new patch number below this line */
+ /**/
+     4389,
  /**/

-- 
Microsoft is to software what McDonalds is to gourmet cooking

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20220215134234.9E4791C0DFF%40moolenaar.net.

Raspunde prin e-mail lui