Patch 8.2.2057
Problem:    Getting the selection may trigger TextYankPost autocmd.
Solution:   Only trigger the autocommand when yanking in Vim, not for getting
            the selection. (closes #7367)
Files:      src/clipboard.c, src/normal.c, src/register.c,
            src/testdir/test_autocmd.vim


*** ../vim-8.2.2056/src/clipboard.c     2020-06-05 20:03:07.461321471 +0200
--- src/clipboard.c     2020-11-26 20:23:06.338621334 +0100
***************
*** 2025,2030 ****
--- 2025,2033 ----
                    && get_y_register(STAR_REGISTER)->y_array != NULL))
            return;
  
+       // Avoid triggering autocmds such as TextYankPost.
+       block_autocmds();
+ 
        // Get the text between clip_star.start & clip_star.end
        old_y_previous = get_y_previous();
        old_y_current = get_y_current();
***************
*** 2054,2059 ****
--- 2057,2064 ----
        curbuf->b_op_end = old_op_end;
        VIsual = old_visual;
        VIsual_mode = old_visual_mode;
+ 
+       unblock_autocmds();
      }
      else if (!is_clipboard_needs_update())
      {
*** ../vim-8.2.2056/src/normal.c        2020-11-12 14:20:32.021927293 +0100
--- src/normal.c        2020-11-26 20:33:20.504702818 +0100
***************
*** 1325,1330 ****
--- 1325,1350 ----
      }
  }
  
+ #if defined(FEAT_CLIPBOARD) && defined(FEAT_EVAL)
+ /*
+  * Call yank_do_autocmd() for "regname".
+  */
+     static void
+ call_yank_do_autocmd(int regname)
+ {
+     oparg_T   oa;
+     yankreg_T *reg;
+ 
+     clear_oparg(&oa);
+     oa.regname = regname;
+     oa.op_type = OP_YANK;
+     oa.is_VIsual = TRUE;
+     reg = get_register(regname, TRUE);
+     yank_do_autocmd(&oa, reg);
+     free_register(reg);
+ }
+ #endif
+ 
  /*
   * End Visual mode.
   * This function should ALWAYS be called to end Visual mode, except from
***************
*** 1342,1347 ****
--- 1362,1379 ----
       */
      if (clip_star.available && clip_star.owned)
        clip_auto_select();
+ 
+ # if defined(FEAT_EVAL)
+     // Emit a TextYankPost for the automatic copy of the selection into the
+     // star and/or plus register.
+     if (has_textyankpost())
+     {
+       if (clip_isautosel_star())
+           call_yank_do_autocmd('*');
+       if (clip_isautosel_plus())
+           call_yank_do_autocmd('+');
+     }
+ # endif
  #endif
  
      VIsual_active = FALSE;
*** ../vim-8.2.2056/src/register.c      2020-10-28 13:53:46.545128969 +0100
--- src/register.c      2020-11-26 20:23:06.338621334 +0100
***************
*** 322,329 ****
  #endif
  }
  
! #if (defined(FEAT_CLIPBOARD) && defined(FEAT_X11) && defined(USE_SYSTEM)) \
!       || defined(PROTO)
      void
  free_register(void *reg)
  {
--- 322,328 ----
  #endif
  }
  
! #if defined(FEAT_CLIPBOARD) || defined(PROTO)
      void
  free_register(void *reg)
  {
*** ../vim-8.2.2056/src/testdir/test_autocmd.vim        2020-11-25 
14:15:08.833986402 +0100
--- src/testdir/test_autocmd.vim        2020-11-26 20:23:06.342621320 +0100
***************
*** 1760,1765 ****
--- 1760,1787 ----
  
    call assert_equal({}, v:event)
  
+   if has('clipboard_working') && !has('gui_running')
+     " Test that when the visual selection is automatically copied to clipboard
+     " register a TextYankPost is emitted
+     call setline(1, ['foobar'])
+ 
+     let @* = ''
+     set clipboard=autoselect
+     exe "norm! ggviw\<Esc>"
+     call assert_equal(
+         \{'regcontents': ['foobar'], 'regname': '*', 'operator': 'y', 
'regtype': 'v', 'visual': v:true},
+         \g:event)
+ 
+     let @+ = ''
+     set clipboard=autoselectplus
+     exe "norm! ggviw\<Esc>"
+     call assert_equal(
+         \{'regcontents': ['foobar'], 'regname': '+', 'operator': 'y', 
'regtype': 'v', 'visual': v:true},
+         \g:event)
+ 
+     set clipboard&vim
+   endif
+ 
    au! TextYankPost
    unlet g:event
    bwipe!
*** ../vim-8.2.2056/src/version.c       2020-11-26 20:11:08.052626187 +0100
--- src/version.c       2020-11-26 20:24:47.674317258 +0100
***************
*** 752,753 ****
--- 752,755 ----
  {   /* Add new patch number below this line */
+ /**/
+     2057,
  /**/

-- 
CUSTOMER:     Well, can you hang around a couple of minutes?  He won't be
              long.
MORTICIAN:    Naaah, I got to go on to Robinson's -- they've lost nine today.
CUSTOMER:     Well, when is your next round?
MORTICIAN:    Thursday.
DEAD PERSON:  I think I'll go for a walk.
                                  The Quest for the Holy Grail (Monty Python)

 /// 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/202011261934.0AQJYtW02450062%40masaka.moolenaar.net.

Raspunde prin e-mail lui