Skip to content

Commit 7132ddc

Browse files
committed
patch 8.1.0187: getwininfo() and win_screenpos() return different numbers
Problem: getwininfo() and win_screenpos() return different numbers. Solution: Add one to "wincol" and "winrow" from getwininfo().
1 parent 44a693a commit 7132ddc

File tree

4 files changed

+51
-46
lines changed

4 files changed

+51
-46
lines changed

runtime/doc/eval.txt

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2196,7 +2196,7 @@ gettabvar({nr}, {varname} [, {def}])
21962196
any variable {varname} in tab {nr} or {def}
21972197
gettabwinvar({tabnr}, {winnr}, {name} [, {def}])
21982198
any {name} in {winnr} in tab page {tabnr}
2199-
getwininfo([{winid}]) List list of windows
2199+
getwininfo([{winid}]) List list of info about each window
22002200
getwinpos([{timeout}]) List X and Y coord in pixels of the Vim window
22012201
getwinposx() Number X coord in pixels of the Vim window
22022202
getwinposy() Number Y coord in pixels of the Vim window
@@ -4936,6 +4936,41 @@ gettabwinvar({tabnr}, {winnr}, {varname} [, {def}]) *gettabwinvar()*
49364936
:let list_is_on = gettabwinvar(1, 2, '&list')
49374937
:echo "myvar = " . gettabwinvar(3, 1, 'myvar')
49384938
<
4939+
getwininfo([{winid}]) *getwininfo()*
4940+
Returns information about windows as a List with Dictionaries.
4941+
4942+
If {winid} is given Information about the window with that ID
4943+
is returned. If the window does not exist the result is an
4944+
empty list.
4945+
4946+
Without {winid} information about all the windows in all the
4947+
tab pages is returned.
4948+
4949+
Each List item is a Dictionary with the following entries:
4950+
bufnr number of buffer in the window
4951+
height window height (excluding winbar)
4952+
winbar 1 if the window has a toolbar, 0
4953+
otherwise
4954+
loclist 1 if showing a location list
4955+
{only with the +quickfix feature}
4956+
quickfix 1 if quickfix or location list window
4957+
{only with the +quickfix feature}
4958+
terminal 1 if a terminal window
4959+
{only with the +terminal feature}
4960+
tabnr tab page number
4961+
variables a reference to the dictionary with
4962+
window-local variables
4963+
width window width
4964+
wincol leftmost screen column of the window,
4965+
col from |win_screenpos()|
4966+
winid |window-ID|
4967+
winnr window number
4968+
winrow topmost screen column of the window,
4969+
row from |win_screenpos()|
4970+
4971+
To obtain all window-local variables use: >
4972+
gettabwinvar({tabnr}, {winnr}, '&')
4973+
49394974
getwinpos([{timeout}]) *getwinpos()*
49404975
The result is a list with two numbers, the result of
49414976
getwinposx() and getwinposy() combined:
@@ -4969,39 +5004,6 @@ getwinposy() The result is a Number, which is the Y coordinate in pixels of
49695004
The result will be -1 if the information is not available.
49705005
The value can be used with `:winpos`.
49715006

4972-
getwininfo([{winid}]) *getwininfo()*
4973-
Returns information about windows as a List with Dictionaries.
4974-
4975-
If {winid} is given Information about the window with that ID
4976-
is returned. If the window does not exist the result is an
4977-
empty list.
4978-
4979-
Without {winid} information about all the windows in all the
4980-
tab pages is returned.
4981-
4982-
Each List item is a Dictionary with the following entries:
4983-
bufnr number of buffer in the window
4984-
height window height (excluding winbar)
4985-
winbar 1 if the window has a toolbar, 0
4986-
otherwise
4987-
loclist 1 if showing a location list
4988-
{only with the +quickfix feature}
4989-
quickfix 1 if quickfix or location list window
4990-
{only with the +quickfix feature}
4991-
terminal 1 if a terminal window
4992-
{only with the +terminal feature}
4993-
tabnr tab page number
4994-
variables a reference to the dictionary with
4995-
window-local variables
4996-
width window width
4997-
wincol leftmost screen column of the window
4998-
winid |window-ID|
4999-
winnr window number
5000-
winrow topmost screen column of the window
5001-
5002-
To obtain all window-local variables use: >
5003-
gettabwinvar({tabnr}, {winnr}, '&')
5004-
50055007
getwinvar({winnr}, {varname} [, {def}]) *getwinvar()*
50065008
Like |gettabwinvar()| for the current tabpage.
50075009
Examples: >
@@ -9049,7 +9051,7 @@ win_id2win({expr}) *win_id2win()*
90499051
win_screenpos({nr}) *win_screenpos()*
90509052
Return the screen position of window {nr} as a list with two
90519053
numbers: [row, col]. The first window always has position
9052-
[1, 1].
9054+
[1, 1], unless there is a tabline, then it is [2, 1].
90539055
{nr} can be the window number or the |window-ID|.
90549056
Return [0, 0] if the window cannot be found in the current
90559057
tabpage.

src/evalfunc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5648,12 +5648,12 @@ get_win_info(win_T *wp, short tpnr, short winnr)
56485648
dict_add_number(dict, "winnr", winnr);
56495649
dict_add_number(dict, "winid", wp->w_id);
56505650
dict_add_number(dict, "height", wp->w_height);
5651-
dict_add_number(dict, "winrow", wp->w_winrow);
5651+
dict_add_number(dict, "winrow", wp->w_winrow + 1);
56525652
#ifdef FEAT_MENU
56535653
dict_add_number(dict, "winbar", wp->w_winbar_height);
56545654
#endif
56555655
dict_add_number(dict, "width", wp->w_width);
5656-
dict_add_number(dict, "wincol", wp->w_wincol);
5656+
dict_add_number(dict, "wincol", wp->w_wincol + 1);
56575657
dict_add_number(dict, "bufnr", wp->w_buffer->b_fnum);
56585658

56595659
#ifdef FEAT_TERMINAL

src/testdir/test_bufwintabinfo.vim

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,22 @@ function Test_getbufwintabinfo()
5252
let winlist = getwininfo()
5353
call assert_equal(5, len(winlist))
5454
call assert_equal(winwidth(1), winlist[0].width)
55-
call assert_equal(0, winlist[0].wincol)
56-
let tablineheight = winlist[0].winrow == 1 ? 1 : 0
57-
call assert_equal(tablineheight, winlist[0].winrow) " tabline adds one
55+
call assert_equal(1, winlist[0].wincol)
56+
" tabline adds one row in terminal, not in GUI
57+
let tablineheight = winlist[0].winrow == 2 ? 1 : 0
58+
call assert_equal(tablineheight + 1, winlist[0].winrow)
5859

5960
call assert_equal(winbufnr(2), winlist[1].bufnr)
6061
call assert_equal(winheight(2), winlist[1].height)
61-
call assert_equal(0, winlist[1].wincol)
62-
call assert_equal(tablineheight + winheight(1) + 1, winlist[1].winrow)
62+
call assert_equal(1, winlist[1].wincol)
63+
call assert_equal(tablineheight + winheight(1) + 2, winlist[1].winrow)
6364

6465
call assert_equal(1, winlist[2].winnr)
65-
call assert_equal(tablineheight, winlist[2].winrow)
66-
call assert_equal(0, winlist[2].wincol)
66+
call assert_equal(tablineheight + 1, winlist[2].winrow)
67+
call assert_equal(1, winlist[2].wincol)
6768

68-
call assert_equal(winlist[2].width + 1, winlist[3].wincol)
69-
call assert_equal(0, winlist[4].wincol)
69+
call assert_equal(winlist[2].width + 2, winlist[3].wincol)
70+
call assert_equal(1, winlist[4].wincol)
7071

7172
call assert_equal(1, winlist[0].tabnr)
7273
call assert_equal(1, winlist[1].tabnr)

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,8 @@ static char *(features[]) =
789789

790790
static int included_patches[] =
791791
{ /* Add new patch number below this line */
792+
/**/
793+
187,
792794
/**/
793795
186,
794796
/**/

0 commit comments

Comments
 (0)