]> granicus.if.org Git - vim/commitdiff
patch 8.0.1786: no test for 'termwinkey' v8.0.1786
authorBram Moolenaar <Bram@vim.org>
Tue, 1 May 2018 16:47:59 +0000 (18:47 +0200)
committerBram Moolenaar <Bram@vim.org>
Tue, 1 May 2018 16:47:59 +0000 (18:47 +0200)
Problem:    No test for 'termwinkey'.
Solution:   Add a test.  Make feedkeys() handle terminal_loop() returning
            before characters are consumed.

src/evalfunc.c
src/ex_docmd.c
src/getchar.c
src/keymap.h
src/terminal.c
src/testdir/test_terminal.vim
src/version.c

index ae1425e53bbdb7861900c50cf2767af3c0a0d7ed..259edb8b1fed0e5fa36323e3e91542f6d9d560b4 100644 (file)
@@ -3311,18 +3311,12 @@ f_feedkeys(typval_T *argvars, typval_T *rettv UNUSED)
                /* Avoid a 1 second delay when the keys start Insert mode. */
                msg_scroll = FALSE;
 
-#ifdef FEAT_TERMINAL
-               if (term_use_loop())
-                   terminal_loop(FALSE);
-               else
-#endif
-               {
-                   if (!dangerous)
-                       ++ex_normal_busy;
-                   exec_normal(TRUE);
-                   if (!dangerous)
-                       --ex_normal_busy;
-               }
+               if (!dangerous)
+                   ++ex_normal_busy;
+               exec_normal(TRUE);
+               if (!dangerous)
+                   --ex_normal_busy;
+
                msg_scroll |= save_msg_scroll;
            }
        }
index 66d2ad6d7b43dd5f7ec65013ed2ed229504592f0..0e2edd65b2d5ac85d14940436be7efa7c3cd1c22 100644 (file)
@@ -10340,7 +10340,21 @@ exec_normal(int was_typed)
                    && typebuf.tb_len > 0)) && !got_int)
     {
        update_topline_cursor();
-       normal_cmd(&oa, TRUE);  /* execute a Normal mode cmd */
+#ifdef FEAT_TERMINAL
+       if (term_use_loop()
+               && oa.op_type == OP_NOP && oa.regname == NUL
+               && !VIsual_active)
+       {
+           /* If terminal_loop() returns OK we got a key that is handled
+            * in Normal model.  With FAIL we first need to position the
+            * cursor and the screen needs to be redrawn. */
+           if (terminal_loop(TRUE) == OK)
+               normal_cmd(&oa, TRUE);
+       }
+       else
+#endif
+           /* execute a Normal mode cmd */
+           normal_cmd(&oa, TRUE);
     }
 }
 
index 623440ecf98266f22f857075c5ae11421a1bec86..5b5b3edabde0bf924099d4719af7a2d03e7e1ee9 100644 (file)
@@ -2059,7 +2059,7 @@ vgetorpeek(int advance)
                    c = inchar(typebuf.tb_buf, typebuf.tb_buflen - 1, 0L);
                    /*
                     * If inchar() returns TRUE (script file was active) or we
-                    * are inside a mapping, get out of insert mode.
+                    * are inside a mapping, get out of Insert mode.
                     * Otherwise we behave like having gotten a CTRL-C.
                     * As a result typing CTRL-C in insert mode will
                     * really insert a CTRL-C.
@@ -2755,6 +2755,10 @@ vgetorpeek(int advance)
                     * cmdline window. */
                    if (p_im && (State & INSERT))
                        c = Ctrl_L;
+#ifdef FEAT_TERMINAL
+                   else if (terminal_is_active())
+                       c = K_CANCEL;
+#endif
                    else if ((State & CMDLINE)
 #ifdef FEAT_CMDWIN
                            || (cmdwin_type > 0 && tc == ESC)
@@ -2898,8 +2902,8 @@ vgetorpeek(int advance)
            }       /* for (;;) */
        }       /* if (!character from stuffbuf) */
 
-                       /* if advance is FALSE don't loop on NULs */
-    } while (c < 0 || (advance && c == NUL));
+       /* if advance is FALSE don't loop on NULs */
+    } while ((c < 0 && c != K_CANCEL) || (advance && c == NUL));
 
     /*
      * The "INSERT" message is taken care of here:
index 8a34f0e296799aeb78686ea9db815465a73f9322..d6dd5cbb35f8568ac67284722c48a1eb5a294af8 100644 (file)
@@ -270,6 +270,7 @@ enum key_extra
     , KE_FOCUSGAINED = 98      /* focus gained */
     , KE_FOCUSLOST = 99                /* focus lost */
     , KE_MOUSEMOVE = 100       /* mouse moved with no button down */
+    , KE_CANCEL = 101          /* return from vgetc() */
 };
 
 /*
@@ -455,6 +456,7 @@ enum key_extra
 
 #define K_IGNORE       TERMCAP2KEY(KS_EXTRA, KE_IGNORE)
 #define K_NOP          TERMCAP2KEY(KS_EXTRA, KE_NOP)
+#define K_CANCEL       TERMCAP2KEY(KS_EXTRA, KE_CANCEL)
 
 #define K_MOUSEDOWN    TERMCAP2KEY(KS_EXTRA, KE_MOUSEDOWN)
 #define K_MOUSEUP      TERMCAP2KEY(KS_EXTRA, KE_MOUSEUP)
index 9b336ee871c66f6f8e357ece724962182edef6db..1fd9ed2abcc93b14bfff3ed38e0718b52eb4771a 100644 (file)
@@ -42,7 +42,6 @@
  *   redirection.  Probably in call to channel_set_pipes().
  * - Win32: Redirecting output does not work, Test_terminal_redir_file()
  *   is disabled.
- * - Add test for 'termwinkey'.
  * - When starting terminal window with shell in terminal, then using :gui to
  *   switch to GUI, shell stops working. Scrollback seems wrong, command
  *   running in shell is still running.
@@ -1690,6 +1689,7 @@ send_keys_to_term(term_T *term, int c, int typed)
            return FAIL;
 
        case K_IGNORE:
+       case K_CANCEL:  // used for :normal when running out of chars
            return FAIL;
 
        case K_LEFTDRAG:
@@ -1826,9 +1826,9 @@ term_paste_register(int prev_c UNUSED)
     }
 }
 
-#if defined(FEAT_GUI) || defined(PROTO)
 /*
- * Return TRUE when the cursor of the terminal should be displayed.
+ * Return TRUE when waiting for a character in the terminal, the cursor of the
+ * terminal should be displayed.
  */
     int
 terminal_is_active()
@@ -1836,6 +1836,7 @@ terminal_is_active()
     return in_terminal_loop != NULL;
 }
 
+#if defined(FEAT_GUI) || defined(PROTO)
     cursorentry_T *
 term_get_cursor_shape(guicolor_T *fg, guicolor_T *bg)
 {
index 0f723466526c223b68bbbfbbe22f4a3dd3d925f9..cde41a1d653adc0341f9e35ecdaaec075e8b8ee1 100644 (file)
@@ -1471,3 +1471,19 @@ func Test_terminal_termwinsize_mininmum()
 
   set termwinsize=
 endfunc
+
+func Test_terminal_termwinkey()
+  call assert_equal(1, winnr('$'))
+  let thiswin = win_getid()
+
+  let buf = Run_shell_in_terminal({})
+  let termwin = bufwinid(buf)
+  set termwinkey=<C-L>
+  call feedkeys("\<C-L>w", 'tx')
+  call assert_equal(thiswin, win_getid())
+  call feedkeys("\<C-W>w", 'tx')
+
+  let job = term_getjob(buf)
+  call feedkeys("\<C-L>\<C-C>", 'tx')
+  call WaitForAssert({-> assert_equal("dead", job_status(job))})
+endfunc
index 01bd9a16e584ebe48722ba2e12c2f7f02eafb7d5..52b54368d84b6c84de022d737c78e36b7845c172 100644 (file)
@@ -761,6 +761,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1786,
 /**/
     1785,
 /**/