]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.0.0739: mouse column not correctly used for popup_setpos v9.0.0739
authorYee Cheng Chin <ychin.git@gmail.com>
Thu, 13 Oct 2022 12:17:40 +0000 (13:17 +0100)
committerBram Moolenaar <Bram@vim.org>
Thu, 13 Oct 2022 12:17:40 +0000 (13:17 +0100)
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)

src/mouse.c
src/testdir/test_termcodes.vim
src/version.c

index 452a30131be559a3201ba6421cf92f02f5b51bef..9efd148ecb536b7ddf74c6acf8fa5e55732c592f 100644 (file)
@@ -141,7 +141,9 @@ find_end_of_word(pos_T *pos)
 # define NEED_VCOL2COL
 
 /*
- * Translate window coordinates to buffer position without any side effects
+ * 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,8 +174,6 @@ get_fpos_of_mouse(pos_T *mpos)
 
     mpos->col = vcol2col(wp, mpos->lnum, col);
 
-    if (mpos->col > 0)
-       --mpos->col;
     mpos->coladd = 0;
     return IN_BUFFER;
 }
@@ -598,7 +598,19 @@ do_mouse(
                        jump_flags = MOUSE_MAY_STOP_VIS;
                    else
                    {
-                       if ((LT_POS(curwin->w_cursor, VIsual)
+                       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)
index cb1d01a0b3debf83e0d4e3ae4d2bf12355cac05c..12c5737ae4b338735c112833858bbfa23f9ec65c 100644 (file)
@@ -1298,20 +1298,20 @@ func Test_term_mouse_popup_menu_setpos()
     call assert_equal([1, 10], [line('.'), col('.')], msg)
     call assert_equal('ran away', @", msg)
 
-    " Test for right click in visual mode before the selection
+    " Test for right click in visual mode right 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 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 after the selection
+    " Test for right click in visual mode right 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 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,6 +1331,32 @@ func Test_term_mouse_popup_menu_setpos()
     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)
index e3a6f360f7e0a198a5f3e8797ed16e30c53a07ef..4014da658a5b8af96fa9152658a3e1a6542198b5 100644 (file)
@@ -699,6 +699,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    739,
 /**/
     738,
 /**/