patch 9.1.1940: clipboard registers "+" and "*" synced without "autoselect"

Problem:  clipboard registers "+" and "*" synced without "autoselect"
Solution: Remove code that explicitly syncs those clipboard registers
          (Corey Hickey)

Before this change, writes to '+' get copied to '*', but only under
certain conditions. By default, this does not happen, because clipboard
"autoselect" (via :set clipboard+=autoselect) is enabled. Disabling
"autoselect" (an option which should only apply to visual mode) results
in normal-mode writes such as "+yy also going to the '*' register.

This behavior is undocumented and untested; remove the behavior in order
to make Vim's handling of these two registers be consistent.

This frees up the did_star variable to be removed.

Add a test to check that the registers are independent.

fixes: #18830
closes: #18831

Signed-off-by: Corey Hickey <bugfood-c@fatooh.org>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
Corey Hickey
2025-11-30 15:16:16 +00:00
committed by Christian Brabandt
parent 6e9694df10
commit aa133f8b3e
3 changed files with 34 additions and 21 deletions

View File

@ -1171,9 +1171,6 @@ op_yank(oparg_T *oap, int deleting, int mess)
linenr_T yankendlnum = oap->end.lnum; linenr_T yankendlnum = oap->end.lnum;
char_u *pnew; char_u *pnew;
struct block_def bd; struct block_def bd;
#if defined(FEAT_CLIPBOARD) && (defined(FEAT_X11) || defined(FEAT_WAYLAND_CLIPBOARD))
int did_star = FALSE;
#endif
// check for read-only register // check for read-only register
if (oap->regname != 0 && !valid_yank_reg(oap->regname, TRUE)) if (oap->regname != 0 && !valid_yank_reg(oap->regname, TRUE))
@ -1397,16 +1394,10 @@ op_yank(oparg_T *oap, int deleting, int mess)
clip_own_selection(&clip_star); clip_own_selection(&clip_star);
clip_gen_set_selection(&clip_star); clip_gen_set_selection(&clip_star);
# if defined(FEAT_X11) || defined(FEAT_WAYLAND_CLIPBOARD)
did_star = TRUE;
# endif
} }
# if defined(FEAT_X11) || defined(FEAT_WAYLAND_CLIPBOARD) # if defined(FEAT_X11) || defined(FEAT_WAYLAND_CLIPBOARD)
// If we were yanking to the '+' register, send result to selection. // If we were yanking to the '+' register, send result to selection.
// Also copy to the '*' register, in case auto-select is off. But not when
// 'clipboard' has "unnamedplus" and not "unnamed"; and not when
// deleting and both "unnamedplus" and "unnamed".
if (clip_plus.available if (clip_plus.available
&& (curr == &(y_regs[PLUS_REGISTER]) && (curr == &(y_regs[PLUS_REGISTER])
|| (!deleting && oap->regname == 0 || (!deleting && oap->regname == 0
@ -1419,18 +1410,6 @@ op_yank(oparg_T *oap, int deleting, int mess)
clip_own_selection(&clip_plus); clip_own_selection(&clip_plus);
clip_gen_set_selection(&clip_plus); clip_gen_set_selection(&clip_plus);
if (!clip_isautosel_star()
&& !clip_isautosel_plus()
&& !((clip_unnamed | clip_unnamed_saved) == CLIP_UNNAMED_PLUS)
&& !(deleting && (clip_unnamed | clip_unnamed_saved)
== (CLIP_UNNAMED | CLIP_UNNAMED_PLUS))
&& !did_star
&& curr == &(y_regs[PLUS_REGISTER]))
{
copy_yank_reg(&(y_regs[STAR_REGISTER]));
clip_own_selection(&clip_star);
clip_gen_set_selection(&clip_star);
}
} }
# endif # endif
#endif #endif

View File

@ -520,6 +520,38 @@ func Test_clipboard_regs()
bwipe! bwipe!
endfunc endfunc
" When clipboard registers (* and +) are supported, check that they are
" independent for direct writes.
func Test_clipboard_regs_separate()
CheckNotGui
CheckFeature clipboard_working
CheckTwoClipboards
new
call setline(1, ['foo'])
" Check that various clipboard options do not result in one register
" affecting the other.
for clip in ['', 'autoselect', 'unnamed', 'unnamedplus']
:execute 'set clipboard=' . clip
" check that * does not affect +
let @* = 'xxx'
let @+ = 'xxx'
:normal "*yw
call assert_equal('foo', getreg('*'))
call assert_equal('xxx', getreg('+'))
" check that + does not affect *
let @* = 'xxx'
:normal "+yw
call assert_equal('foo', getreg('+'))
call assert_equal('xxx', getreg('*'))
endfor
set clipboard&vim
bwipe!
endfunc
" Test unnamed for both clipboard registers (* and +) " Test unnamed for both clipboard registers (* and +)
func Test_clipboard_regs_both_unnamed() func Test_clipboard_regs_both_unnamed()
CheckNotGui CheckNotGui

View File

@ -729,6 +729,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1940,
/**/ /**/
1939, 1939,
/**/ /**/