]> granicus.if.org Git - vim/commitdiff
patch 8.0.1364: there is no easy way to get the window position v8.0.1364
authorBram Moolenaar <Bram@vim.org>
Sat, 2 Dec 2017 14:43:37 +0000 (15:43 +0100)
committerBram Moolenaar <Bram@vim.org>
Sat, 2 Dec 2017 14:43:37 +0000 (15:43 +0100)
Problem:    There is no easy way to get the window position.
Solution:   Add win_screenpos().

runtime/doc/eval.txt
src/evalfunc.c
src/testdir/test_window_cmd.vim
src/version.c

index 29b3de887a5c508d065018601722932d7b1daa8d..4d524679d33941e5cb62a64259ff8f217f73f8b2 100644 (file)
@@ -2452,6 +2452,7 @@ win_getid([{win} [, {tab}]])      Number  get window ID for {win} in {tab}
 win_gotoid({expr})             Number  go to window with ID {expr}
 win_id2tabwin({expr})          List    get tab and window nr from window ID
 win_id2win({expr})             Number  get window nr from window ID
+win_screenpos({nr})            List    get screen position of window {nr}
 winbufnr({nr})                 Number  buffer number of window {nr}
 wincol()                       Number  window column of the cursor
 winheight({nr})                        Number  height of window {nr}
@@ -8633,6 +8634,14 @@ win_id2win({expr})                                       *win_id2win()*
                Return the window number of window with ID {expr}.
                Return 0 if the window cannot be found in the current tabpage.
 
+win_screenpos({nr})                                    *win_screenpos()*
+               Return the screen position of window {nr} as a list with two
+               numbers: [row, col].  The first window always has position
+               [1, 1].
+               {nr} can be the window number or the |window-ID|.
+               Return [0, 0] if the window cannot be found in the current
+               tabpage.
+
                                                        *winbufnr()*
 winbufnr({nr}) The result is a Number, which is the number of the buffer
                associated with window {nr}.  {nr} can be the window number or
index 76c576855e7f00729d0a1b001a2905a4ccc273c1..72690847276185481fc54c81eae62936d294dbda 100644 (file)
@@ -441,6 +441,7 @@ static void f_win_getid(typval_T *argvars, typval_T *rettv);
 static void f_win_gotoid(typval_T *argvars, typval_T *rettv);
 static void f_win_id2tabwin(typval_T *argvars, typval_T *rettv);
 static void f_win_id2win(typval_T *argvars, typval_T *rettv);
+static void f_win_screenpos(typval_T *argvars, typval_T *rettv);
 static void f_winbufnr(typval_T *argvars, typval_T *rettv);
 static void f_wincol(typval_T *argvars, typval_T *rettv);
 static void f_winheight(typval_T *argvars, typval_T *rettv);
@@ -899,6 +900,7 @@ static struct fst
     {"win_gotoid",     1, 1, f_win_gotoid},
     {"win_id2tabwin",  1, 1, f_win_id2tabwin},
     {"win_id2win",     1, 1, f_win_id2win},
+    {"win_screenpos",  1, 1, f_win_screenpos},
     {"winbufnr",       1, 1, f_winbufnr},
     {"wincol",         0, 0, f_wincol},
     {"winheight",      1, 1, f_winheight},
@@ -5378,6 +5380,22 @@ f_win_id2win(typval_T *argvars, typval_T *rettv)
     rettv->vval.v_number = win_id2win(argvars);
 }
 
+/*
+ * "win_screenpos()" function
+ */
+    static void
+f_win_screenpos(typval_T *argvars, typval_T *rettv)
+{
+    win_T      *wp;
+
+    if (rettv_list_alloc(rettv) == FAIL)
+       return;
+
+    wp = find_win_by_nr(&argvars[0], NULL);
+    list_append_number(rettv->vval.v_list, wp == NULL ? 0 : wp->w_winrow + 1);
+    list_append_number(rettv->vval.v_list, wp == NULL ? 0 : wp->w_wincol + 1);
+}
+
 /*
  * "getwinposx()" function
  */
index 49bd9fa689bcd2077fb18d566de253b2b47b1332..067f09cbc3007af1189fdb0b3cf7058dc3ac69aa 100644 (file)
@@ -362,6 +362,19 @@ func Test_equalalways_on_close()
   set equalalways&
 endfunc
 
+func Test_win_screenpos()
+  call assert_equal(1, winnr('$'))
+  split
+  vsplit
+  10wincmd _
+  30wincmd |
+  call assert_equal([1, 1], win_screenpos(1))
+  call assert_equal([1, 32], win_screenpos(2))
+  call assert_equal([12, 1], win_screenpos(3))
+  call assert_equal([0, 0], win_screenpos(4))
+  only
+endfunc
+
 func Test_window_jump_tag()
   help
   /iccf
index 8587b4dfeded08877ac155a3a703455259594643..e85058edea55d7b16b3707d0dac6cba5352390e4 100644 (file)
@@ -771,6 +771,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1364,
 /**/
     1363,
 /**/