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/normal.c b/src/normal.c
index 87f1956..d90326f 100644
--- a/src/normal.c
+++ b/src/normal.c
@@ -1325,6 +1325,26 @@
}
}
+#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,6 +1362,18 @@
*/
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;