]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1940: clipboard registers "+" and "*" synced without "autoselect" v9.1.1940
authorCorey Hickey <bugfood-c@fatooh.org>
Sun, 30 Nov 2025 15:16:16 +0000 (15:16 +0000)
committerChristian Brabandt <cb@256bit.org>
Sun, 30 Nov 2025 15:16:16 +0000 (15:16 +0000)
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>
src/register.c
src/testdir/test_registers.vim
src/version.c

index 524ada4ca4ef42855d335f25d698df5071d12769..52afe793c85a840006bd84ba07ce98e47ef38591 100644 (file)
@@ -1171,9 +1171,6 @@ op_yank(oparg_T *oap, int deleting, int mess)
     linenr_T           yankendlnum = oap->end.lnum;
     char_u             *pnew;
     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
     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_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 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
            && (curr == &(y_regs[PLUS_REGISTER])
                || (!deleting && oap->regname == 0
@@ -1419,18 +1410,6 @@ op_yank(oparg_T *oap, int deleting, int mess)
 
        clip_own_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
index dee1cd73966d6a32f21b22bd17f8eb80e2c55221..0910369633c18a149aedd70306831933a87bdcea 100644 (file)
@@ -520,6 +520,38 @@ func Test_clipboard_regs()
   bwipe!
 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 +)
 func Test_clipboard_regs_both_unnamed()
   CheckNotGui
index 13ec4924d0feed67a7f11886647bd4ada0e84505..392e833708e1e29ddd649855426ca8bf74c0867e 100644 (file)
@@ -729,6 +729,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1940,
 /**/
     1939,
 /**/