Commit: patch 9.2.0791: wincol() counts from right side for 'rightleft'

2 views
Skip to first unread message

Christian Brabandt

unread,
9:15 AM (9 hours ago) 9:15 AM
to vim...@googlegroups.com
patch 9.2.0791: wincol() counts from right side for 'rightleft'

Commit: https://github.com/vim/vim/commit/95a1932e87bbb9c90842a4341d5c6f0efa99fe7a
Author: Sergey Vlasov <ser...@vlasov.me>
Date: Sat Jul 18 13:11:06 2026 +0000

patch 9.2.0791: wincol() counts from right side for 'rightleft'

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 <ser...@vlasov.me>
Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/src/evalwindow.c b/src/evalwindow.c
index c93979e08..23cd92b67 100644
--- a/src/evalwindow.c
+++ b/src/evalwindow.c
@@ -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;
}

/*
diff --git a/src/testdir/test_functions.vim b/src/testdir/test_functions.vim
index d2e5f6e21..988218342 100644
--- a/src/testdir/test_functions.vim
+++ b/src/testdir/test_functions.vim
@@ -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
diff --git a/src/version.c b/src/version.c
index f9abe4fa1..77d596c04 100644
--- a/src/version.c
+++ b/src/version.c
@@ -759,6 +759,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 791,
/**/
790,
/**/
Reply all
Reply to author
Forward
0 new messages