Problem: Getting the selection may trigger TextYankPost autocmd.
Solution: Only trigger the autocommand when yanking in Vim, not for getting
the selection. (closes #7367)
&& 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();
curbuf->b_op_end = old_op_end;
VIsual = old_visual;
VIsual_mode = old_visual_mode;
+
+ unblock_autocmds();
}
else if (!is_clipboard_needs_update())
{
}
}
+#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
*/
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;
#endif
}
-#if (defined(FEAT_CLIPBOARD) && defined(FEAT_X11) && defined(USE_SYSTEM)) \
- || defined(PROTO)
+#if defined(FEAT_CLIPBOARD) || defined(PROTO)
void
free_register(void *reg)
{
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!
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 2057,
/**/
2056,
/**/