Patch 9.0.0739
Problem:    Mouse column not correctly used for popup_setpos.
Solution:   Adjust off-by-one error and handle Visual line selection properly.
            (Yee Cheng Chin, closes #11356)
Files:      src/mouse.c, src/testdir/test_termcodes.vim


*** ../vim-9.0.0738/src/mouse.c 2022-10-04 16:23:39.018042176 +0100
--- src/mouse.c 2022-10-13 13:05:44.879745093 +0100
***************
*** 141,147 ****
  # define NEED_VCOL2COL
  
  /*
!  * Translate window coordinates to buffer position without any side effects
   */
      static int
  get_fpos_of_mouse(pos_T *mpos)
--- 141,149 ----
  # define NEED_VCOL2COL
  
  /*
!  * Translate window coordinates to buffer position without any side effects.
!  * Returns IN_BUFFER and sets "mpos->col" to the column when in buffer text.
!  * The column is one for the first column.
   */
      static int
  get_fpos_of_mouse(pos_T *mpos)
***************
*** 172,179 ****
  
      mpos->col = vcol2col(wp, mpos->lnum, col);
  
-     if (mpos->col > 0)
-       --mpos->col;
      mpos->coladd = 0;
      return IN_BUFFER;
  }
--- 174,179 ----
***************
*** 598,604 ****
                        jump_flags = MOUSE_MAY_STOP_VIS;
                    else
                    {
!                       if ((LT_POS(curwin->w_cursor, VIsual)
                                    && (LT_POS(m_pos, curwin->w_cursor)
                                        || LT_POS(VIsual, m_pos)))
                                || (LT_POS(VIsual, curwin->w_cursor)
--- 598,616 ----
                        jump_flags = MOUSE_MAY_STOP_VIS;
                    else
                    {
!                       if (VIsual_mode == 'V')
!                       {
!                           if ((curwin->w_cursor.lnum <= VIsual.lnum
!                                   && (m_pos.lnum < curwin->w_cursor.lnum
!                                       || VIsual.lnum < m_pos.lnum))
!                               || (VIsual.lnum < curwin->w_cursor.lnum
!                                   && (m_pos.lnum < VIsual.lnum
!                                       || curwin->w_cursor.lnum < m_pos.lnum)))
!                           {
!                               jump_flags = MOUSE_MAY_STOP_VIS;
!                           }
!                       }
!                       else if ((LTOREQ_POS(curwin->w_cursor, VIsual)
                                    && (LT_POS(m_pos, curwin->w_cursor)
                                        || LT_POS(VIsual, m_pos)))
                                || (LT_POS(VIsual, curwin->w_cursor)
*** ../vim-9.0.0738/src/testdir/test_termcodes.vim      2022-10-05 
11:24:42.228494178 +0100
--- src/testdir/test_termcodes.vim      2022-10-13 13:02:47.387508198 +0100
***************
*** 1298,1317 ****
      call assert_equal([1, 10], [line('.'), col('.')], msg)
      call assert_equal('ran away', @", msg)
  
!     " Test for right click in visual mode before the selection
      let @" = ''
      call cursor(1, 10)
!     call feedkeys('vee' .. MouseRightClickCode(1, 2)
!               \ .. MouseRightReleaseCode(1, 2) .. "\<Down>\<CR>", "x")
!     call assert_equal([1, 2], [line('.'), col('.')], msg)
      call assert_equal('', @", msg)
  
!     " Test for right click in visual mode after the selection
      let @" = ''
      call cursor(1, 10)
!     call feedkeys('vee' .. MouseRightClickCode(1, 20)
!               \ .. MouseRightReleaseCode(1, 20) .. "\<Down>\<CR>", "x")
!     call assert_equal([1, 20], [line('.'), col('.')], msg)
      call assert_equal('', @", msg)
  
      " Test for right click in block-wise visual mode inside the selection
--- 1298,1317 ----
      call assert_equal([1, 10], [line('.'), col('.')], msg)
      call assert_equal('ran away', @", msg)
  
!     " Test for right click in visual mode right before the selection
      let @" = ''
      call cursor(1, 10)
!     call feedkeys('vee' .. MouseRightClickCode(1, 9)
!               \ .. MouseRightReleaseCode(1, 9) .. "\<Down>\<CR>", "x")
!     call assert_equal([1, 9], [line('.'), col('.')], msg)
      call assert_equal('', @", msg)
  
!     " Test for right click in visual mode right after the selection
      let @" = ''
      call cursor(1, 10)
!     call feedkeys('vee' .. MouseRightClickCode(1, 18)
!               \ .. MouseRightReleaseCode(1, 18) .. "\<Down>\<CR>", "x")
!     call assert_equal([1, 18], [line('.'), col('.')], msg)
      call assert_equal('', @", msg)
  
      " Test for right click in block-wise visual mode inside the selection
***************
*** 1331,1336 ****
--- 1331,1362 ----
      call assert_equal('v', getregtype('"'), msg)
      call assert_equal('', @", msg)
  
+     " Test for right click in line-wise visual mode inside the selection
+     let @" = ''
+     call cursor(1, 16)
+     call feedkeys("V" .. MouseRightClickCode(1, 10)
+               \ .. MouseRightReleaseCode(1, 10) .. "\<Down>\<CR>", "x")
+     call assert_equal([1, 1], [line('.'), col('.')], msg) " After yanking, 
the cursor goes to 1,1
+     call assert_equal("V", getregtype('"'), msg)
+     call assert_equal(len(getreg('"', 1, v:true)), 1, msg)
+ 
+     " Test for right click in multi-line line-wise visual mode inside the 
selection
+     let @" = ''
+     call cursor(1, 16)
+     call feedkeys("Vj" .. MouseRightClickCode(2, 20)
+               \ .. MouseRightReleaseCode(2, 20) .. "\<Down>\<CR>", "x")
+     call assert_equal([1, 1], [line('.'), col('.')], msg) " After yanking, 
the cursor goes to 1,1
+     call assert_equal("V", getregtype('"'), msg)
+     call assert_equal(len(getreg('"', 1, v:true)), 2, msg)
+ 
+     " Test for right click in line-wise visual mode outside the selection
+     let @" = ''
+     call cursor(1, 16)
+     call feedkeys("V" .. MouseRightClickCode(2, 10)
+               \ .. MouseRightReleaseCode(2, 10) .. "\<Down>\<CR>", "x")
+     call assert_equal([2, 10], [line('.'), col('.')], msg)
+     call assert_equal("", @", msg)
+ 
      " Try clicking on the status line
      let @" = ''
      call cursor(1, 10)
*** ../vim-9.0.0738/src/version.c       2022-10-13 12:51:09.544145472 +0100
--- src/version.c       2022-10-13 13:04:34.507670786 +0100
***************
*** 701,702 ****
--- 701,704 ----
  {   /* Add new patch number below this line */
+ /**/
+     739,
  /**/

-- 
   [SIR LAUNCELOT runs back up the stairs, grabs a rope
   of the wall and swings out over the heads of the CROWD in a
   swashbuckling manner towards a large window.  He stops just short
   of the window and is left swing pathetically back and forth.]
LAUNCELOT: Excuse me ... could somebody give me a push ...
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

 /// 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/20221013121815.DC96E1C5296%40moolenaar.net.

Raspunde prin e-mail lui