Skip to content

Commit 761a484

Browse files
64-bitmanchrisbra
authored andcommitted
patch 9.1.1860: clipboard register "+" enabled with cplipboard provider feature
Problem: clipboard register "+" enabled with cplipboard provider feature (BenYip, after v9.1.1857) Solution: Don't make clipboard provider enable plus register on UNIX (Foxe Chen) fixes: #18580 closes: #18580 Signed-off-by: Foxe Chen <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent 6180d65 commit 761a484

4 files changed

Lines changed: 60 additions & 35 deletions

File tree

runtime/doc/eval.txt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*eval.txt* For Vim version 9.1. Last change: 2025 Oct 14
1+
*eval.txt* For Vim version 9.1. Last change: 2025 Oct 16
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -5274,8 +5274,9 @@ Usage: >vim
52745274

52755275
When Vim is compiled with the |+clipboard_provider| feature, which requires
52765276
the |+eval| feature, creating custom clipboards is possible. These providers
5277-
handle the "+" and "*" registers. Note that on non-Unix or non-VMS systems,
5278-
only the "*" register will be available for use.
5277+
handle the "+" and "*" registers. Note that if |+wayland_clipboard| or
5278+
|+xterm_clipboard| features are not compiled in, then the "+" register will
5279+
not be available.
52795280

52805281
To add a provider, add a new entry to the |v:clipproviders| dictionary, in the
52815282
format of: >
@@ -5353,7 +5354,7 @@ Here is an example script that uses the clipboard provider feature through the
53535354
OSC52 command: >vim
53545355

53555356
func Available()
5356-
return "+"
5357+
return "*"
53575358
endfunc
53585359

53595360
func Paste(reg, type)
@@ -5368,7 +5369,7 @@ OSC52 command: >vim
53685369
augroup END
53695370

53705371
" Send command
5371-
call echoraw("\<Esc>]52;c;?\<Esc>\\")
5372+
call echoraw("\<Esc>]52;;?\<Esc>\\")
53725373

53735374
" Wait until autocmd is triggered
53745375
while getchar(-1) != "\<F30>"
@@ -5377,7 +5378,7 @@ OSC52 command: >vim
53775378
autocmd! OSC
53785379

53795380
" Extract the base64 stuff
5380-
let l:stuff = matchstr(v:termosc, '52;c;\zs[A-Za-z0-9+/=]\+')
5381+
let l:stuff = matchstr(v:termosc, '52;.\+;\zs[A-Za-z0-9+/=]\+')
53815382

53825383
return ("", blob2str(base64_decode(l:stuff)))
53835384
endfunc
@@ -5389,10 +5390,10 @@ OSC52 command: >vim
53895390
let v:clipproviders["myosc"] = {
53905391
\ "available": function("Available"),
53915392
\ "paste": {
5392-
\ '+': function("Paste"),
5393+
\ '*': function("Paste")
53935394
\ },
53945395
\ "copy": {
5395-
\ '+': function("Copy"),
5396+
\ '*': function("Copy")
53965397
\ },
53975398
\ }
53985399
set clipmethod=myosc

src/clipboard.c

Lines changed: 48 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3466,7 +3466,7 @@ clip_wl_owner_exists(Clipboard_T *cbd)
34663466
* depending on the order of values in str.
34673467
*/
34683468
static clipmethod_T
3469-
get_clipmethod(char_u *str, bool *regular, bool *primary)
3469+
get_clipmethod(char_u *str, bool *plus UNUSED, bool *star)
34703470
{
34713471
int len = (int)STRLEN(str) + 1;
34723472
char_u *buf = alloc(len);
@@ -3493,8 +3493,8 @@ get_clipmethod(char_u *str, bool *regular, bool *primary)
34933493
if (clip_wl.regular.available || clip_wl.primary.available)
34943494
{
34953495
method = CLIPMETHOD_WAYLAND;
3496-
*regular = clip_wl.regular.available;
3497-
*primary = clip_wl.primary.available;
3496+
*plus = clip_wl.regular.available;
3497+
*star = clip_wl.primary.available;
34983498
}
34993499
#endif
35003500
}
@@ -3516,7 +3516,7 @@ get_clipmethod(char_u *str, bool *regular, bool *primary)
35163516
// won't be executed since xterm_dpy will be set to NULL.
35173517
xterm_update();
35183518
method = CLIPMETHOD_X11;
3519-
*regular = *primary = true;
3519+
*plus = *star = true;
35203520
}
35213521
#endif
35223522
}
@@ -3527,35 +3527,48 @@ get_clipmethod(char_u *str, bool *regular, bool *primary)
35273527
if (gui.in_use)
35283528
{
35293529
method = CLIPMETHOD_GUI;
3530-
*regular = *primary = true;
3530+
*star = *plus = true;
35313531
}
35323532
#endif
35333533
}
35343534
else if (STRCMP(buf, "other") == 0)
35353535
{
35363536
#ifndef UNIX
35373537
method = CLIPMETHOD_OTHER;
3538-
*regular = *primary = true;
3538+
*plus = *star = true;
35393539
#endif
35403540
}
35413541
else
35423542
{
35433543
#ifdef FEAT_CLIPBOARD_PROVIDER
35443544
// Check if it is the name of a provider
3545-
int reg = clip_provider_is_available(&clip_plus, buf);
3546-
int pri = clip_provider_is_available(&clip_star, buf);
3545+
#ifndef ONE_CLIPBOARD
3546+
int plus_avail = clip_provider_is_available(&clip_plus, buf);
3547+
#endif
3548+
int star_avail = clip_provider_is_available(&clip_star, buf);
35473549

3548-
if (reg == 1 || pri == 1)
3550+
if (
3551+
#ifndef ONE_CLIPBOARD
3552+
plus_avail == 1 ||
3553+
#endif
3554+
star_avail == 1)
35493555
{
35503556
method = CLIPMETHOD_PROVIDER;
35513557

35523558
vim_free(clipprovider_name);
35533559
clipprovider_name = vim_strsave(buf);
35543560

3555-
*regular = reg == 1;
3556-
*primary = pri == 1;
3561+
#ifndef ONE_CLIPBOARD
3562+
*plus = plus_avail == 1;
3563+
#endif
3564+
*star = star_avail == 1;
35573565
}
3558-
else if (reg == -1)
3566+
3567+
else if (
3568+
#ifndef ONE_CLIPBOARD
3569+
plus_avail == -1 ||
3570+
#endif
3571+
star_avail == -1)
35593572
#endif
35603573
{
35613574
ret = CLIPMETHOD_FAIL;
@@ -3614,8 +3627,9 @@ clipmethod_to_str(clipmethod_T method)
36143627
char *
36153628
choose_clipmethod(void)
36163629
{
3617-
bool regular = false, primary = false;
3618-
clipmethod_T method = get_clipmethod(p_cpm, &regular, &primary);
3630+
bool plus = false;
3631+
bool star = false;
3632+
clipmethod_T method = get_clipmethod(p_cpm, &plus, &star);
36193633

36203634
if (method == CLIPMETHOD_FAIL)
36213635
return e_invalid_argument;
@@ -3633,30 +3647,35 @@ choose_clipmethod(void)
36333647
// If we have a clipmethod that works now, then initialize clipboard
36343648
else if (clipmethod == CLIPMETHOD_NONE && method != CLIPMETHOD_NONE)
36353649
{
3636-
clip_init_single(&clip_plus, regular);
3637-
clip_init_single(&clip_star, primary);
3650+
#ifndef ONE_CLIPBOARD
3651+
clip_init_single(&clip_plus, plus);
36383652
clip_plus.did_warn = false;
3653+
#endif
3654+
clip_init_single(&clip_star, star);
36393655
clip_star.did_warn = false;
36403656
}
36413657
else if ((clipmethod != CLIPMETHOD_NONE && method != clipmethod))
36423658
{
36433659
// Disown clipboard if we are switching to a new method
36443660
if (clip_star.owned)
36453661
clip_lose_selection(&clip_star);
3662+
clip_init_single(&clip_star, star);
3663+
#ifndef ONE_CLIPBOARD
36463664
if (clip_plus.owned)
36473665
clip_lose_selection(&clip_plus);
3648-
3649-
clip_init_single(&clip_plus, regular);
3650-
clip_init_single(&clip_star, primary);
3666+
clip_init_single(&clip_plus, plus);
3667+
#endif
36513668
}
36523669
else
36533670
{
36543671
// If availability of a clipboard changed, then update the clipboard
36553672
// structure.
3656-
if (regular != clip_plus.available)
3657-
clip_init_single(&clip_plus, regular);
3658-
if (primary != clip_star.available)
3659-
clip_init_single(&clip_star, primary);
3673+
#ifndef ONE_CLIPBOARD
3674+
if (plus != clip_plus.available)
3675+
clip_init_single(&clip_plus, plus);
3676+
#endif
3677+
if (star != clip_star.available)
3678+
clip_init_single(&clip_star, star);
36603679
}
36613680

36623681
clipmethod = method;
@@ -3724,8 +3743,12 @@ clip_provider_is_available(Clipboard_T *cbd, char_u *provider)
37243743

37253744
avail = rettv.vval.v_string;
37263745

3727-
if ((vim_strchr(avail, '+') != NULL && cbd == &clip_plus)
3728-
|| (vim_strchr(avail, '*') != NULL && cbd == &clip_star))
3746+
3747+
if (
3748+
#ifndef ONE_CLIPBOARD
3749+
(vim_strchr(avail, '+') != NULL && cbd == &clip_plus) ||
3750+
#endif
3751+
(vim_strchr(avail, '*') != NULL && cbd == &clip_star))
37293752
res = 1;
37303753

37313754
if (FALSE)

src/globals.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -972,8 +972,7 @@ EXTERN int gui_win_y INIT(= -1);
972972

973973
#ifdef FEAT_CLIPBOARD
974974
EXTERN Clipboard_T clip_star; // PRIMARY selection in X11/Wayland
975-
# if defined(FEAT_X11) || defined(FEAT_WAYLAND_CLIPBOARD) \
976-
|| ((defined(UNIX) || defined(VMS)) && defined(FEAT_CLIPBOARD_PROVIDER))
975+
# if defined(FEAT_X11) || defined(FEAT_WAYLAND_CLIPBOARD)
977976
EXTERN Clipboard_T clip_plus; // CLIPBOARD selection in X11/Wayland
978977
# else
979978
# define clip_plus clip_star // there is only one clipboard

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,8 @@ static char *(features[]) =
734734

735735
static int included_patches[] =
736736
{ /* Add new patch number below this line */
737+
/**/
738+
1860,
737739
/**/
738740
1859,
739741
/**/

0 commit comments

Comments
 (0)