]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0791: wincol() counts from right side for 'rightleft' v9.2.0791
authorSergey Vlasov <sergey@vlasov.me>
Sat, 18 Jul 2026 13:11:06 +0000 (13:11 +0000)
committerChristian Brabandt <cb@256bit.org>
Sat, 18 Jul 2026 13:11:06 +0000 (13:11 +0000)
Problem:  wincol() counts cells from right side of the window if
          'rightleft' is enabled.
Solution: Fix wincol() to count from left side of the window
          as documented (Sergey Vlasov).

closes: #20763

Signed-off-by: Sergey Vlasov <sergey@vlasov.me>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/evalwindow.c
src/testdir/test_functions.vim
src/version.c

index c93979e08c4b5f1149f9de51c48a71882051413f..23cd92b677d42b56aee2741b80b4519995789786 100644 (file)
@@ -1126,7 +1126,12 @@ f_winbufnr(typval_T *argvars, typval_T *rettv)
 f_wincol(typval_T *argvars UNUSED, typval_T *rettv)
 {
     validate_cursor();
-    rettv->vval.v_number = curwin->w_wcol + 1;
+    int col = curwin->w_wcol + 1;
+# ifdef FEAT_RIGHTLEFT
+    if (curwin->w_p_rl)
+       col = curwin->w_width - col + 1;
+# endif
+    rettv->vval.v_number = col;
 }
 
 /*
index d2e5f6e21a07db9b55ebb9b4371c1f5e95618473..988218342923b649f07ec509eff72d3cb399b2ab 100644 (file)
@@ -1,6 +1,7 @@
 " Tests for various functions.
 
 source util/screendump.vim
+source util/view_util.vim
 import './util/vim9.vim' as v9
 
 " Must be done first, since the alternate buffer must be unset.
@@ -4705,4 +4706,40 @@ func Test_vim9_def_defer_fc_sandbox()
   delfunction g:BadDefer
 endfunc
 
+" Test wincol() counts in screen cells from left side of the window
+func Test_wincol()
+  enew!
+  set ff=unix mouse=a
+
+  let win_width = 30
+  call NewWindow(20, win_width)
+
+  call setline(1, "the quick brown fox jump")
+
+  norm! 0
+  call assert_equal([1, 1], [winline(), wincol()])
+
+  call test_setmouse(1, 10)
+  call feedkeys("\<LeftMouse>\<Ignore>", "xt")
+  call assert_equal([1, 10], [winline(), wincol()])
+
+  if has('rightleft')
+    norm! 0
+    call assert_equal([1, 1], [winline(), wincol()])
+
+    set rightleft
+    " cursor is still at column 1, but in screen cells it is at the distance of window width:
+    call assert_equal([1, win_width], [winline(), wincol()])
+
+    " test_setmouse() works in screen coordinates, which is not affected by 'rightleft':
+    call test_setmouse(1, 10)
+    call feedkeys("\<LeftMouse>\<Ignore>", "xt")
+    call assert_equal([1, 10], [winline(), wincol()])
+    set rightleft&
+  endif
+
+  set ff& mouse&
+  bw!
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index f9abe4fa15daefcf5566a7ddaa73b8a8aaf20139..77d596c04e6d207d7d1252f3caca45bf850df20e 100644 (file)
@@ -759,6 +759,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    791,
 /**/
     790,
 /**/