]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.0.1923: curswant wrong on click with 've' and 'wrap' set v9.0.1923
authorzeertzjq <zeertzjq@outlook.com>
Thu, 21 Sep 2023 14:33:09 +0000 (16:33 +0200)
committerChristian Brabandt <cb@256bit.org>
Thu, 21 Sep 2023 14:33:09 +0000 (16:33 +0200)
Problem:  curswant wrong on click with 've' and 'wrap' set
Solution: Add w_leftcol to mouse click column.

closes: #13142

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: zeertzjq <zeertzjq@outlook.com>
src/drawline.c
src/mouse.c
src/screen.c
src/testdir/test_virtualedit.vim
src/version.c

index 6f9044650aeb8379750f991baecf4d55b17396a3..95ea3f025a12c4c56c28355d281ecd157822246c 100644 (file)
@@ -3852,7 +3852,14 @@ win_line(
            else
                ScreenAttrs[wlv.off] = wlv.char_attr;
 
-           ScreenCols[wlv.off] = wlv.vcol;
+           if (wlv.draw_state > WL_NR
+#ifdef FEAT_DIFF
+                   && wlv.filler_todo <= 0
+#endif
+                   )
+               ScreenCols[wlv.off] = wlv.vcol;
+           else
+               ScreenCols[wlv.off] = -1;
 
            if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
            {
@@ -3865,19 +3872,21 @@ win_line(
                else
                    // DBCS: Put second byte in the second screen char.
                    ScreenLines[wlv.off] = mb_c & 0xff;
+
                if (wlv.draw_state > WL_NR
 #ifdef FEAT_DIFF
                        && wlv.filler_todo <= 0
 #endif
                        )
-                   ++wlv.vcol;
+                   ScreenCols[wlv.off] = ++wlv.vcol;
+               else
+                   ScreenCols[wlv.off] = -1;
+
                // When "wlv.tocol" is halfway a character, set it to the end
                // of the character, otherwise highlighting won't stop.
                if (wlv.tocol == wlv.vcol)
                    ++wlv.tocol;
 
-               ScreenCols[wlv.off] = wlv.vcol;
-
 #ifdef FEAT_RIGHTLEFT
                if (wp->w_p_rl)
                {
index ec036737590df0acee120cb3dce726ac0cd8a6f2..f3342f905699091f8c14ff8f0df873b466542b93 100644 (file)
@@ -2115,11 +2115,16 @@ retnomove:
                else
                    off_r = off_m - 1;
            }
-           col = ScreenCols[off_r] + (off_click - off_r);
+           colnr_T eol_vcol = ScreenCols[off_r];
+           if (eol_vcol < 0)
+               // Empty line or whole line before w_leftcol,
+               // with columns before buffer text
+               eol_vcol = curwin->w_leftcol - 1;
+           col = eol_vcol + (off_click - off_r);
        }
        else
-           // Clicking on an empty line
-           col = prev_col - curwin->w_wincol;
+           // Empty line or whole line before w_leftcol
+           col = prev_col - curwin->w_wincol + curwin->w_leftcol;
     }
     else if (col_from_screen >= 0)
     {
index b4f55fe5107248b7e8207be3d991444fb92948c7..bb905fe51893063686acf6955581f51de8236fcd 100644 (file)
@@ -18,8 +18,8 @@
  *                  displayed (excluding text written by external commands).
  * ScreenAttrs[off]  Contains the associated attributes.
  * ScreenCols[off]   Contains the virtual columns in the line. -1 means not
- *                  available (below last line), MAXCOL means after the end
- *                  of the line.
+ *                  available or before buffer text, MAXCOL means after the
+ *                  end of the line.
  *
  * LineOffset[row]   Contains the offset into ScreenLines*[], ScreenAttrs[]
  *                  and ScreenCols[] for each line.
index 0cd5e9675ec11b1686bf79d90e25ee3911321a19..9f254c65a43978f5129b7f0900dd6c9fafc9b836 100644 (file)
@@ -599,6 +599,61 @@ func Test_virtualedit_mouse()
   call feedkeys("\<LeftMouse>", "xt")
   call assert_equal([0, 1, 10, 2, 15], getcurpos())
 
+  setlocal nowrap
+  call setline(2, repeat('a', 19))
+  normal! j14zl
+  redraw
+  call test_setmouse(row, 21 + 1)
+  call feedkeys("\<LeftMouse>", "xt")
+  call assert_equal([0, 1, 10, 2, 15], getcurpos())
+  call test_setmouse(row, 21 + 11)
+  call feedkeys("\<LeftMouse>", "xt")
+  call assert_equal([0, 1, 10, 12, 25], getcurpos())
+  call test_setmouse(row + 1, 21 + 1)
+  call feedkeys("\<LeftMouse>", "xt")
+  call assert_equal([0, 2, 15, 0, 15], getcurpos())
+  call test_setmouse(row + 1, 21 + 11)
+  call feedkeys("\<LeftMouse>", "xt")
+  call assert_equal([0, 2, 20, 5, 25], getcurpos())
+
+  setlocal number numberwidth=2
+  redraw
+  call test_setmouse(row, 21 + 3)
+  call feedkeys("\<LeftMouse>", "xt")
+  call assert_equal([0, 1, 10, 2, 15], getcurpos())
+  call test_setmouse(row, 21 + 13)
+  call feedkeys("\<LeftMouse>", "xt")
+  call assert_equal([0, 1, 10, 12, 25], getcurpos())
+  call test_setmouse(row + 1, 21 + 3)
+  call feedkeys("\<LeftMouse>", "xt")
+  call assert_equal([0, 2, 15, 0, 15], getcurpos())
+  call test_setmouse(row + 1, 21 + 13)
+  call feedkeys("\<LeftMouse>", "xt")
+  call assert_equal([0, 2, 20, 5, 25], getcurpos())
+  setlocal nonumber
+
+  if has('signs')
+    sign define Sign1 text=口
+    sign place 1 name=Sign1 line=1
+    sign place 2 name=Sign1 line=2
+    redraw
+    call test_setmouse(row, 21 + 3)
+    call feedkeys("\<LeftMouse>", "xt")
+    call assert_equal([0, 1, 10, 2, 15], getcurpos())
+    call test_setmouse(row, 21 + 13)
+    call feedkeys("\<LeftMouse>", "xt")
+    call assert_equal([0, 1, 10, 12, 25], getcurpos())
+    call test_setmouse(row + 1, 21 + 3)
+    call feedkeys("\<LeftMouse>", "xt")
+    call assert_equal([0, 2, 15, 0, 15], getcurpos())
+    call test_setmouse(row + 1, 21 + 13)
+    call feedkeys("\<LeftMouse>", "xt")
+    call assert_equal([0, 2, 20, 5, 25], getcurpos())
+    sign unplace 1
+    sign unplace 2
+    sign undefine Sign1
+  endif
+
   bwipe!
   let &mouse = save_mouse
   set virtualedit&
index 7e8589b05ce0b6f8381688dcece9c48d7a384630..c088942889e2211ff0d78e34a3499b50d6c0b64b 100644 (file)
@@ -699,6 +699,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1923,
 /**/
     1922,
 /**/