patch 8.2.2057: getting the selection may trigger TextYankPost autocmd

Problem:    Getting the selection may trigger TextYankPost autocmd.
Solution:   Only trigger the autocommand when yanking in Vim, not for getting
            the selection. (closes #7367)
diff --git a/src/testdir/test_autocmd.vim b/src/testdir/test_autocmd.vim
index 890d28f..c51f37f 100644
--- a/src/testdir/test_autocmd.vim
+++ b/src/testdir/test_autocmd.vim
@@ -1760,6 +1760,28 @@
 
   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!