]> granicus.if.org Git - vim/commitdiff
patch 8.2.4692: no test for what 8.2.4691 fixes v8.2.4692
authorzeertzjq <zeertzjq@outlook.com>
Tue, 5 Apr 2022 12:17:01 +0000 (13:17 +0100)
committerBram Moolenaar <Bram@vim.org>
Tue, 5 Apr 2022 12:17:01 +0000 (13:17 +0100)
Problem:    No test for what 8.2.4691 fixes.
Solution:   Add a test.  Use a more generic sotlution. (closes #10090)

src/getchar.c
src/mouse.c
src/testdir/test_mapping.vim
src/version.c

index 34a33ac40b2317bdcaa8f5eb48ba6b090d63cf02..b81f64a65c0aeeae7440a0bd69ad3e270575ccc3 100644 (file)
@@ -1419,6 +1419,14 @@ static int old_char = -1;        // character put back by vungetc()
 static int old_mod_mask;       // mod_mask for ungotten character
 static int old_mouse_row;      // mouse_row related to old_char
 static int old_mouse_col;      // mouse_col related to old_char
+static int old_KeyStuffed;     // whether old_char was stuffed
+
+static int can_get_old_char()
+{
+    // If the old character was not stuffed and characters have been added to
+    // the stuff buffer, need to first get the stuffed characters instead.
+    return old_char != -1 && (old_KeyStuffed || stuff_empty());
+}
 
 /*
  * Save all three kinds of typeahead, so that the user must type at a prompt.
@@ -1687,7 +1695,7 @@ vgetc(void)
      * If a character was put back with vungetc, it was already processed.
      * Return it directly.
      */
-    if (old_char != -1)
+    if (can_get_old_char())
     {
        c = old_char;
        old_char = -1;
@@ -1987,7 +1995,7 @@ plain_vgetc(void)
     int
 vpeekc(void)
 {
-    if (old_char != -1)
+    if (can_get_old_char())
        return old_char;
     return vgetorpeek(FALSE);
 }
@@ -2942,6 +2950,8 @@ handle_mapping(
 
 /*
  * unget one character (can only be done once!)
+ * If the character was stuffed, vgetc() will get it next time it was called.
+ * Otherwise vgetc() will only get it when the stuff buffer is empty.
  */
     void
 vungetc(int c)
@@ -2950,6 +2960,7 @@ vungetc(int c)
     old_mod_mask = mod_mask;
     old_mouse_row = mouse_row;
     old_mouse_col = mouse_col;
+    old_KeyStuffed = KeyStuffed;
 }
 
 /*
@@ -3755,8 +3766,6 @@ getcmdkeycmd(
     int                c2;
     int                cmod = 0;
     int                aborted = FALSE;
-    int                first = TRUE;
-    int                got_ctrl_o = FALSE;
 
     ga_init2(&line_ga, 1, 32);
 
@@ -3784,15 +3793,6 @@ getcmdkeycmd(
        // Get one character at a time.
        c1 = vgetorpeek(TRUE);
 
-       // do not use Ctrl_O at the start, stuff it back later
-       if (first && c1 == Ctrl_O)
-       {
-           got_ctrl_o = TRUE;
-           first = FALSE;
-           continue;
-       }
-       first = FALSE;
-
        // Get two extra bytes for special keys
        if (c1 == K_SPECIAL)
        {
@@ -3844,8 +3844,6 @@ getcmdkeycmd(
     }
 
     no_mapping--;
-    if (got_ctrl_o)
-       stuffcharReadbuff(Ctrl_O);
 
     if (aborted)
        ga_clear(&line_ga);
index b81aff2487ede34be13ce91adfe760a075bb8eec..42963341c574ab4c48fa8a7e32bc9f3d3aa780a2 100644 (file)
@@ -261,7 +261,10 @@ do_mouse(
        {
            // If the next character is the same mouse event then use that
            // one. Speeds up dragging the status line.
-           if (vpeekc() != NUL)
+           // Note: Since characters added to the stuff buffer in the code
+           // below need to come before the next character, do not do this
+           // when the current character was stuffed.
+           if (!KeyStuffed && vpeekc() != NUL)
            {
                int nc;
                int save_mouse_row = mouse_row;
index 6421058b02035bc597fc7472b95ca38a9b256ad5..a002126f16b60e6fedf9ec539cf01804f29583b1 100644 (file)
@@ -1566,4 +1566,37 @@ func Test_plug_remap()
   %bw!
 endfunc
 
+" Test for mapping <LeftDrag> in Insert mode
+func Test_mouse_drag_insert_map()
+  set mouse=a
+  func ClickExpr()
+    call test_setmouse(1, 1)
+    return "\<LeftMouse>"
+  endfunc
+  func DragExpr()
+    call test_setmouse(1, 2)
+    return "\<LeftDrag>"
+  endfunc
+  inoremap <expr> <F2> ClickExpr()
+  imap <expr> <F3> DragExpr()
+
+  inoremap <LeftDrag> <LeftDrag><Cmd>let g:dragged = 1<CR>
+  exe "normal i\<F2>\<F3>"
+  call assert_equal(1, g:dragged)
+  call assert_equal('v', mode())
+  exe "normal! \<C-\>\<C-N>"
+  unlet g:dragged
+
+  inoremap <LeftDrag> <LeftDrag><C-\><C-N>
+  exe "normal i\<F2>\<F3>"
+  call assert_equal('n', mode())
+
+  iunmap <LeftDrag>
+  iunmap <F2>
+  iunmap <F3>
+  delfunc ClickExpr
+  delfunc DragExpr
+  set mouse&
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 9e50d2facd689ec1c7d3b6a1d1286239b863fd5b..4451f7d91e3a0b568ad15d175814ad52be40e96d 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4692,
 /**/
     4691,
 /**/