Patch 8.2.0839
Problem:    Dropping modifier when putting a character back in typeahead.
Solution:   Add modifier to ins_char_typebuf(). (closes #6158)
Files:      src/getchar.c, src/proto/getchar.pro, src/message.c, src/normal.c,
            src/terminal.c, src/globals.h, src/testdir/test_messages.vim


*** ../vim-8.2.0838/src/getchar.c       2020-05-28 21:03:49.505375147 +0200
--- src/getchar.c       2020-05-29 22:18:33.442791491 +0200
***************
*** 1101,1118 ****
   * the char.
   */
      void
! ins_char_typebuf(int c)
  {
!     char_u    buf[MB_MAXBYTES + 1];
!     if (IS_SPECIAL(c))
      {
        buf[0] = K_SPECIAL;
!       buf[1] = K_SECOND(c);
!       buf[2] = K_THIRD(c);
        buf[3] = NUL;
      }
      else
!       buf[(*mb_char2bytes)(c, buf)] = NUL;
      (void)ins_typebuf(buf, KeyNoremap, 0, !KeyTyped, cmd_silent);
  }
  
--- 1101,1129 ----
   * the char.
   */
      void
! ins_char_typebuf(int c, int modifier)
  {
!     char_u    buf[MB_MAXBYTES + 4];
!     int               idx = 0;
! 
!     if (modifier != 0)
      {
        buf[0] = K_SPECIAL;
!       buf[1] = KS_MODIFIER;
!       buf[2] = modifier;
        buf[3] = NUL;
+       idx = 3;
+     }
+     if (IS_SPECIAL(c))
+     {
+       buf[idx] = K_SPECIAL;
+       buf[idx + 1] = K_SECOND(c);
+       buf[idx + 2] = K_THIRD(c);
+       buf[idx + 3] = NUL;
+       idx += 3;
      }
      else
!       buf[(*mb_char2bytes)(c, buf + idx) + idx] = NUL;
      (void)ins_typebuf(buf, KeyNoremap, 0, !KeyTyped, cmd_silent);
  }
  
***************
*** 1640,1647 ****
      }
      else
      {
!       mod_mask = 0x0;
        last_recorded_len = 0;
        for (;;)                // this is done twice if there are modifiers
        {
            int did_inc = FALSE;
--- 1651,1661 ----
      }
      else
      {
!       mod_mask = 0;
!       vgetc_mod_mask = 0;
!       vgetc_char = 0;
        last_recorded_len = 0;
+ 
        for (;;)                // this is done twice if there are modifiers
        {
            int did_inc = FALSE;
***************
*** 1835,1843 ****
--- 1849,1863 ----
            }
  
            if (!no_reduce_keys)
+           {
                // A modifier was not used for a mapping, apply it to ASCII
                // keys.  Shift would already have been applied.
+               // Remember the character and mod_mask from before, in some
+               // cases they are put back in the typeahead buffer.
+               vgetc_mod_mask = mod_mask;
+               vgetc_char = c;
                c = merge_modifyOtherKeys(c);
+           }
  
            break;
        }
***************
*** 2192,2198 ****
      // If the current window or buffer changed we need to bail out of the
      // waiting loop.  E.g. when a job exit callback closes the terminal 
window.
      if (curwin->w_id != old_curwin_id || curbuf->b_fnum != old_curbuf_fnum)
!       ins_char_typebuf(K_IGNORE);
  
      --entered;
  }
--- 2212,2218 ----
      // If the current window or buffer changed we need to bail out of the
      // waiting loop.  E.g. when a job exit callback closes the terminal 
window.
      if (curwin->w_id != old_curwin_id || curbuf->b_fnum != old_curbuf_fnum)
!       ins_char_typebuf(K_IGNORE, 0);
  
      --entered;
  }
*** ../vim-8.2.0838/src/proto/getchar.pro       2020-05-01 14:26:17.132949262 
+0200
--- src/proto/getchar.pro       2020-05-29 22:06:37.957828407 +0200
***************
*** 25,31 ****
  void stop_redo_ins(void);
  int noremap_keys(void);
  int ins_typebuf(char_u *str, int noremap, int offset, int nottyped, int 
silent);
! void ins_char_typebuf(int c);
  int typebuf_changed(int tb_change_cnt);
  int typebuf_typed(void);
  int typebuf_maplen(void);
--- 25,31 ----
  void stop_redo_ins(void);
  int noremap_keys(void);
  int ins_typebuf(char_u *str, int noremap, int offset, int nottyped, int 
silent);
! void ins_char_typebuf(int c, int modifier);
  int typebuf_changed(int tb_change_cnt);
  int typebuf_typed(void);
  int typebuf_maplen(void);
*** ../vim-8.2.0838/src/message.c       2020-04-25 15:45:34.480027272 +0200
--- src/message.c       2020-05-29 22:35:58.078759462 +0200
***************
*** 1258,1264 ****
        {
            // Put the character back in the typeahead buffer.  Don't use the
            // stuff buffer, because lmaps wouldn't work.
!           ins_char_typebuf(c);
            do_redraw = TRUE;       // need a redraw even though there is
                                    // typeahead
        }
--- 1258,1264 ----
        {
            // Put the character back in the typeahead buffer.  Don't use the
            // stuff buffer, because lmaps wouldn't work.
!           ins_char_typebuf(vgetc_char, vgetc_mod_mask);
            do_redraw = TRUE;       // need a redraw even though there is
                                    // typeahead
        }
***************
*** 3712,3718 ****
                if (c == ':' && ex_cmd)
                {
                    retval = dfltbutton;
!                   ins_char_typebuf(':');
                    break;
                }
  
--- 3712,3718 ----
                if (c == ':' && ex_cmd)
                {
                    retval = dfltbutton;
!                   ins_char_typebuf(':', 0);
                    break;
                }
  
*** ../vim-8.2.0838/src/normal.c        2020-05-12 22:02:17.889963176 +0200
--- src/normal.c        2020-05-29 22:40:57.149825051 +0200
***************
*** 595,601 ****
        // restart automatically.
        // Insert the typed character in the typeahead buffer, so that it can
        // be mapped in Insert mode.  Required for ":lmap" to work.
!       ins_char_typebuf(c);
        if (restart_edit != 0)
            c = 'd';
        else
--- 595,601 ----
        // restart automatically.
        // Insert the typed character in the typeahead buffer, so that it can
        // be mapped in Insert mode.  Required for ":lmap" to work.
!       ins_char_typebuf(vgetc_char, vgetc_mod_mask);
        if (restart_edit != 0)
            c = 'd';
        else
*** ../vim-8.2.0838/src/terminal.c      2020-05-27 21:22:10.184851569 +0200
--- src/terminal.c      2020-05-29 22:06:23.529889733 +0200
***************
*** 3467,3473 ****
        redraw_statuslines();
  
        // Need to break out of vgetc().
!       ins_char_typebuf(K_IGNORE);
        typebuf_was_filled = TRUE;
  
        term = curbuf->b_term;
--- 3467,3473 ----
        redraw_statuslines();
  
        // Need to break out of vgetc().
!       ins_char_typebuf(K_IGNORE, 0);
        typebuf_was_filled = TRUE;
  
        term = curbuf->b_term;
*** ../vim-8.2.0838/src/globals.h       2020-05-25 22:36:46.629735032 +0200
--- src/globals.h       2020-05-29 22:20:39.470257198 +0200
***************
*** 120,126 ****
   * When vgetc() is called, it sets mod_mask to the set of modifiers that are
   * held down based on the MOD_MASK_* symbols that are read first.
   */
! EXTERN int    mod_mask INIT(= 0x0);           // current key modifiers
  
  /*
   * Cmdline_row is the row where the command line starts, just below the
--- 120,131 ----
   * When vgetc() is called, it sets mod_mask to the set of modifiers that are
   * held down based on the MOD_MASK_* symbols that are read first.
   */
! EXTERN int    mod_mask INIT(= 0);             // current key modifiers
! 
! // The value of "mod_mask" and the unomdified character before calling
! // merge_modifyOtherKeys().
! EXTERN int    vgetc_mod_mask INIT(= 0);
! EXTERN int    vgetc_char INIT(= 0);
  
  /*
   * Cmdline_row is the row where the command line starts, just below the
*** ../vim-8.2.0838/src/testdir/test_messages.vim       2020-04-30 
19:19:25.812908797 +0200
--- src/testdir/test_messages.vim       2020-05-29 22:34:09.819054970 +0200
***************
*** 2,7 ****
--- 2,8 ----
  
  source shared.vim
  source term_util.vim
+ source view_util.vim
  
  func Test_messages()
    let oldmore = &more
***************
*** 305,308 ****
--- 306,317 ----
    endif
  endfunc
  
+ func Test_mapping_at_hit_return_prompt()
+   nnoremap <C-B> :echo "hit ctrl-b"<CR>
+   call feedkeys(":ls\<CR>", "xt")
+   call feedkeys("\<C-B>", "xt")
+   call assert_match('hit ctrl-b', Screenline(&lines - 1))
+   nunmap <C-B>
+ endfunc
+ 
  " vim: shiftwidth=2 sts=2 expandtab
*** ../vim-8.2.0838/src/version.c       2020-05-29 21:42:51.192004289 +0200
--- src/version.c       2020-05-29 22:05:50.078032006 +0200
***************
*** 748,749 ****
--- 748,751 ----
  {   /* Add new patch number below this line */
+ /**/
+     839,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
205. You're constantly yelling at your spouse, family, roommate, whatever,
     for using the phone for stupid things...like talking.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/202005292042.04TKgCIR155147%40masaka.moolenaar.net.

Raspunde prin e-mail lui