]> granicus.if.org Git - vim/commitdiff
patch 8.2.0257: cannot recognize a terminal in a popup window v8.2.0257
authorBram Moolenaar <Bram@vim.org>
Fri, 14 Feb 2020 13:32:22 +0000 (14:32 +0100)
committerBram Moolenaar <Bram@vim.org>
Fri, 14 Feb 2020 13:32:22 +0000 (14:32 +0100)
Problem:    Cannot recognize a terminal in a popup window.
Solution:   Add the win_gettype() function.

runtime/doc/eval.txt
src/evalfunc.c
src/evalwindow.c
src/proto/evalwindow.pro
src/testdir/dumps/Test_terminal_popup_1.dump
src/testdir/test_cmdline.vim
src/testdir/test_terminal.vim
src/version.c

index d7c0dc3a8b1fb8fb62e497e26bd6a71f689a6fd5..765d83637595391d56e5d4035736981a75d50a2c 100644 (file)
@@ -10328,6 +10328,23 @@ win_getid([{win} [, {tab}]])                           *win_getid()*
                Can also be used as a |method|: >
                        GetWinnr()->win_getid()
 
+
+win_gettype([{nr}])                                    *win_gettype()*
+               Return the type of the window:
+                       "popup"         popup window |popup|
+                       "command"       command-line window |cmdwin|
+                       (empty)         normal window
+                       "unknown"       window {nr} not found
+
+               When {nr} is omitted return the type of the current window.
+               When {nr} is given return the type of this window by number or
+               |window-ID|.
+
+               Also see the 'buftype' option.  When running a terminal in a
+               popup window then 'buftype' is "terminal" and win_gettype()
+               returns "popup".
+
+
 win_gotoid({expr})                                     *win_gotoid()*
                Go to window with ID {expr}.  This may also change the current
                tabpage.
index b4009f0aefb58db14da57a2615bef79c3cfeaa45..a0f29943ec93cf2d88e096b9193548cdafc3fe19 100644 (file)
@@ -86,7 +86,6 @@ static void f_garbagecollect(typval_T *argvars, typval_T *rettv);
 static void f_get(typval_T *argvars, typval_T *rettv);
 static void f_getchangelist(typval_T *argvars, typval_T *rettv);
 static void f_getcharsearch(typval_T *argvars, typval_T *rettv);
-static void f_getcmdwintype(typval_T *argvars, typval_T *rettv);
 static void f_getenv(typval_T *argvars, typval_T *rettv);
 static void f_getfontname(typval_T *argvars, typval_T *rettv);
 static void f_getjumplist(typval_T *argvars, typval_T *rettv);
@@ -845,6 +844,7 @@ static funcentry_T global_functions[] =
     {"win_execute",    2, 3, FEARG_2,    &t_string,    f_win_execute},
     {"win_findbuf",    1, 1, FEARG_1,    &t_list_number, f_win_findbuf},
     {"win_getid",      0, 2, FEARG_1,    &t_number,    f_win_getid},
+    {"win_gettype",    0, 1, FEARG_1,    &t_string,    f_win_gettype},
     {"win_gotoid",     1, 1, FEARG_1,    &t_number,    f_win_gotoid},
     {"win_id2tabwin",  1, 1, FEARG_1,    &t_list_number, f_win_id2tabwin},
     {"win_id2win",     1, 1, FEARG_1,    &t_number,    f_win_id2win},
@@ -2919,24 +2919,6 @@ f_getcharsearch(typval_T *argvars UNUSED, typval_T *rettv)
     }
 }
 
-/*
- * "getcmdwintype()" function
- */
-    static void
-f_getcmdwintype(typval_T *argvars UNUSED, typval_T *rettv)
-{
-    rettv->v_type = VAR_STRING;
-    rettv->vval.v_string = NULL;
-#ifdef FEAT_CMDWIN
-    rettv->vval.v_string = alloc(2);
-    if (rettv->vval.v_string != NULL)
-    {
-       rettv->vval.v_string[0] = cmdwin_type;
-       rettv->vval.v_string[1] = NUL;
-    }
-#endif
-}
-
 /*
  * "getenv()" function
  */
index be6762a5c6ebf74b3ed8fb16c5577756bc5ca8c4..c7a9f7960eeee1ef0d6d7f184f3be9853f8f239b 100644 (file)
@@ -839,6 +839,54 @@ f_win_splitmove(typval_T *argvars, typval_T *rettv)
     win_move_into_split(wp, targetwin, size, flags);
 }
 
+/*
+ * "win_gettype(nr)" function
+ */
+    void
+f_win_gettype(typval_T *argvars, typval_T *rettv)
+{
+    win_T      *wp = curwin;
+
+    rettv->v_type = VAR_STRING;
+    rettv->vval.v_string = NULL;
+    if (argvars[0].v_type != VAR_UNKNOWN)
+    {
+       wp = find_win_by_nr_or_id(&argvars[0]);
+       if (wp == NULL)
+       {
+           rettv->vval.v_string = vim_strsave((char_u *)"unknown");
+           return;
+       }
+    }
+#ifdef FEAT_PROP_POPUP
+    if (WIN_IS_POPUP(wp))
+       rettv->vval.v_string = vim_strsave((char_u *)"popup");
+    else
+#endif
+#ifdef FEAT_CMDWIN
+    if (wp == curwin && cmdwin_type != 0)
+       rettv->vval.v_string = vim_strsave((char_u *)"command");
+#endif
+}
+
+/*
+ * "getcmdwintype()" function
+ */
+    void
+f_getcmdwintype(typval_T *argvars UNUSED, typval_T *rettv)
+{
+    rettv->v_type = VAR_STRING;
+    rettv->vval.v_string = NULL;
+#ifdef FEAT_CMDWIN
+    rettv->vval.v_string = alloc(2);
+    if (rettv->vval.v_string != NULL)
+    {
+       rettv->vval.v_string[0] = cmdwin_type;
+       rettv->vval.v_string[1] = NUL;
+    }
+#endif
+}
+
 /*
  * "winbufnr(nr)" function
  */
index e3faa96eb595d78472bcb648eb88e176026f1cf9..4eb1ced8bc8df8b26890d526aa2f9fd87520f0f8 100644 (file)
@@ -20,6 +20,8 @@ void f_win_id2tabwin(typval_T *argvars, typval_T *rettv);
 void f_win_id2win(typval_T *argvars, typval_T *rettv);
 void f_win_screenpos(typval_T *argvars, typval_T *rettv);
 void f_win_splitmove(typval_T *argvars, typval_T *rettv);
+void f_win_gettype(typval_T *argvars, typval_T *rettv);
+void f_getcmdwintype(typval_T *argvars, typval_T *rettv);
 void f_winbufnr(typval_T *argvars, typval_T *rettv);
 void f_wincol(typval_T *argvars, typval_T *rettv);
 void f_winheight(typval_T *argvars, typval_T *rettv);
index 0628eb08fe1d93638c97c2ef3cb2224977e3b9df..8c2a54d8483298eabdf3ff79bbd7fc73ef60481b 100644 (file)
@@ -8,8 +8,8 @@
 |7| @12|║+0#0000001#ffd7ff255|~+0#4040ff13#ffffff0| @43|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@13
 |8| @12|║+0#0000001#ffd7ff255|~+0#4040ff13#ffffff0| @43|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@13
 |9| @12|║+0#0000001#ffd7ff255|~+0#4040ff13#ffffff0| @43|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@13
-|1|0| @11|║+0#0000001#ffd7ff255|"+0#0000000#ffffff0|X|t|e|x|t|"| |3|L|,| |3|6|C| @11|1|,|1| @10|A|l@1| |║+0#0000001#ffd7ff255| +0#0000000#ffffff0@13
+|1|0| @11|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@26|1|,|1| @10|A|l@1| |║+0#0000001#ffd7ff255| +0#0000000#ffffff0@13
 |1@1| @11|╚+0#0000001#ffd7ff255|═@44|⇲| +0#0000000#ffffff0@13
 |1|2| @72
 |1|3| @72
-@57|0|,|0|-|1| @8|A|l@1| 
+|t|e|r|m|i|n|a|l| |p|o|p|u|p| @42|0|,|0|-|1| @8|A|l@1| 
index a3d2d5a736574af93720a31a9efde6090bf03291..27ebfbcda1121e8884639d1f58211955da3310f8 100644 (file)
@@ -894,12 +894,14 @@ func Test_cmdwin_cedit()
   let g:cmd_wintype = ''
   func CmdWinType()
       let g:cmd_wintype = getcmdwintype()
+      let g:wintype = win_gettype()
       return ''
   endfunc
 
   call feedkeys("\<C-c>a\<C-R>=CmdWinType()\<CR>\<CR>")
   echo input('')
   call assert_equal('@', g:cmd_wintype)
+  call assert_equal('command', g:wintype)
 
   set cedit&vim
   delfunc CmdWinType
index 8c1d3572a63cd9a4b0de3e7241f56844baf5176c..993498cddd9eeddbaa8cb0362fc76660ee4d15dd 100644 (file)
@@ -2333,6 +2333,7 @@ func Test_terminal_in_popup()
   call writefile(text, 'Xtext')
   let cmd = GetVimCommandCleanTerm()
   let lines = [
+       \ 'set t_u7=',
        \ 'call setline(1, range(20))',
        \ 'hi PopTerm ctermbg=grey',
        \ 'func OpenTerm(setColor)',
@@ -2346,6 +2347,9 @@ func Test_terminal_in_popup()
        \ 'func HidePopup()',
        \ '  call popup_hide(s:winid)',
        \ 'endfunc',
+       \ 'sleep 10m',
+       \ 'redraw',
+       \ 'echo getwinvar(s:winid, "&buftype") win_gettype(s:winid)',
        \ ]
   call writefile(lines, 'XtermPopup')
   let buf = RunVimInTerminal('-S XtermPopup', #{rows: 15})
index 73ea73690cffc4f8c1d8e2c304f8cefcccef53d8..70ea449a3542967f5a36492b2caa1e8d90a7204d 100644 (file)
@@ -742,6 +742,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    257,
 /**/
     256,
 /**/