patch 9.1.0186: cursor pos wrong on mouse click after eol with 'rl', 've' and 
conceal

Commit: 
https://github.com/vim/vim/commit/deb2204bffa075ed5485415fc2dbd20e75d87ea4
Author: zeertzjq <[email protected]>
Date:   Sun Mar 17 19:44:30 2024 +0100

    patch 9.1.0186: cursor pos wrong on mouse click after eol with 'rl', 've' 
and conceal
    
    Problem:  Wrong cursor position when clicking after end of line with
              'rightleft', 'virtualedit' and conceal.
    Solution: Set values in ScreenCols[] also with SLF_RIGHTLEFT.  Also fix
              off-by-one cursor position with 'colorcolumn' (zeertzjq).
    
    closes: #14218
    
    Signed-off-by: zeertzjq <[email protected]>
    Signed-off-by: Christian Brabandt <[email protected]>

diff --git a/src/drawline.c b/src/drawline.c
index cc1bed6b1..ed02f3cab 100644
--- a/src/drawline.c
+++ b/src/drawline.c
@@ -975,15 +975,14 @@ draw_screen_line(win_T *wp, winlinevars_T *wlv)
                ++wlv->off;
                ++wlv->col;
            }
+           ++wlv->vcol;
 
-           if (VCOL_HLC >= rightmost_vcol
+           if (VCOL_HLC > rightmost_vcol
 # ifdef LINE_ATTR
                    && wlv->line_attr == 0
 # endif
                    && wlv->win_attr == 0)
                break;
-
-           ++wlv->vcol;
        }
     }
 #endif
diff --git a/src/screen.c b/src/screen.c
index 08b1c018f..71ddbcaab 100644
--- a/src/screen.c
+++ b/src/screen.c
@@ -18,8 +18,7 @@
  *                  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 or before buffer text, MAXCOL means after the
- *                  end of the line.
+ *                  available or before buffer text.
  *
  * LineOffset[row]   Contains the offset into ScreenLines*[], ScreenAttrs[]
  *                  and ScreenCols[] for each line.
@@ -509,6 +508,8 @@ screen_line(
        // Clear rest first, because it's left of the text.
        if (clear_width > 0)
        {
+           int clear_start = col;
+
            while (col <= endcol && ScreenLines[off_to] == ' '
                    && ScreenAttrs[off_to] == 0
                                  && (!enc_utf8 || ScreenLinesUC[off_to] == 0))
@@ -519,6 +520,10 @@ screen_line(
            if (col <= endcol)
                screen_fill(row, row + 1, col + coloff,
                                            endcol + coloff + 1, ' ', ' ', 0);
+
+           for (int i = endcol; i >= clear_start; i--)
+               ScreenCols[off_to + (i - col)] =
+                   (flags & SLF_INC_VCOL) ? ++last_vcol : last_vcol;
        }
        col = endcol + 1;
        off_to = LineOffset[row] + col + coloff;
diff --git a/src/testdir/test_conceal.vim b/src/testdir/test_conceal.vim
index 9696cdeae..355817dd3 100644
--- a/src/testdir/test_conceal.vim
+++ b/src/testdir/test_conceal.vim
@@ -464,6 +464,53 @@ func Test_conceal_mouse_click()
     call test_setmouse(1, 32)
     call feedkeys("\<LeftMouse>", "tx")
     call assert_equal([0, 1, 24, 12, 36], getcurpos())
+    " Behavior should also be the same with 'colorcolumn'.
+    setlocal colorcolumn=30
+    redraw
+    call test_setmouse(1, 31)
+    call feedkeys("\<LeftMouse>", "tx")
+    call assert_equal([0, 1, 24, 11, 35], getcurpos())
+    call test_setmouse(1, 32)
+    call feedkeys("\<LeftMouse>", "tx")
+    call assert_equal([0, 1, 24, 12, 36], getcurpos())
+    setlocal colorcolumn&
+
+    if has('rightleft')
+      setlocal rightleft
+      call assert_equal([
+            \ '                     ereh kcilc  laecnoc',
+            \ ], ScreenLines(1, 40))
+      " Click on the space between "this" and "click" puts cursor there.
+      call test_setmouse(1, 41 - 9)
+      call feedkeys("\<LeftMouse>", "tx")
+      call assert_equal([0, 1, 13, 0, 13], getcurpos())
+      " Click on 'h' of "here" puts cursor there.
+      call test_setmouse(1, 41 - 16)
+      call feedkeys("\<LeftMouse>", "tx")
+      call assert_equal([0, 1, 20, 0, 20], getcurpos())
+      " Click on 'e' of "here" puts cursor there.
+      call test_setmouse(1, 41 - 19)
+      call feedkeys("\<LeftMouse>", "tx")
+      call assert_equal([0, 1, 23, 0, 23], getcurpos())
+      " Click after end of line puts cursor there with 'virtualedit'.
+      call test_setmouse(1, 41 - 20)
+      call feedkeys("\<LeftMouse>", "tx")
+      call assert_equal([0, 1, 24, 0, 24], getcurpos())
+      call test_setmouse(1, 41 - 21)
+      call feedkeys("\<LeftMouse>", "tx")
+      call assert_equal([0, 1, 24, 1, 25], getcurpos())
+      call test_setmouse(1, 41 - 22)
+      call feedkeys("\<LeftMouse>", "tx")
+      call assert_equal([0, 1, 24, 2, 26], getcurpos())
+      call test_setmouse(1, 41 - 31)
+      call feedkeys("\<LeftMouse>", "tx")
+      call assert_equal([0, 1, 24, 11, 35], getcurpos())
+      call test_setmouse(1, 41 - 32)
+      call feedkeys("\<LeftMouse>", "tx")
+      call assert_equal([0, 1, 24, 12, 36], getcurpos())
+      setlocal rightleft&
+    endif
+
     set virtualedit&
 
     " Test with a wrapped line.
diff --git a/src/version.c b/src/version.c
index 07bed4f30..d09022807 100644
--- a/src/version.c
+++ b/src/version.c
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    186,
 /**/
     185,
 /**/

-- 
-- 
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/E1rlvjm-007c7Q-Qm%40256bit.org.

Raspunde prin e-mail lui