forked from aniani/vim
patch 8.2.0443: clipboard code is spread out
Problem: Clipboard code is spread out. Solution: Move clipboard code to its own file. (Yegappan Lakshmanan, closes #5827)
This commit is contained in:
107
src/ops.c
107
src/ops.c
@@ -3409,113 +3409,6 @@ theend:
|
||||
return did_change;
|
||||
}
|
||||
|
||||
#if defined(FEAT_CLIPBOARD) || defined(PROTO)
|
||||
/*
|
||||
* SELECTION / PRIMARY ('*')
|
||||
*
|
||||
* Text selection stuff that uses the GUI selection register '*'. When using a
|
||||
* GUI this may be text from another window, otherwise it is the last text we
|
||||
* had highlighted with VIsual mode. With mouse support, clicking the middle
|
||||
* button performs the paste, otherwise you will need to do <"*p>. "
|
||||
* If not under X, it is synonymous with the clipboard register '+'.
|
||||
*
|
||||
* X CLIPBOARD ('+')
|
||||
*
|
||||
* Text selection stuff that uses the GUI clipboard register '+'.
|
||||
* Under X, this matches the standard cut/paste buffer CLIPBOARD selection.
|
||||
* It will be used for unnamed cut/pasting is 'clipboard' contains "unnamed",
|
||||
* otherwise you will need to do <"+p>. "
|
||||
* If not under X, it is synonymous with the selection register '*'.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Routine to export any final X selection we had to the environment
|
||||
* so that the text is still available after Vim has exited. X selections
|
||||
* only exist while the owning application exists, so we write to the
|
||||
* permanent (while X runs) store CUT_BUFFER0.
|
||||
* Dump the CLIPBOARD selection if we own it (it's logically the more
|
||||
* 'permanent' of the two), otherwise the PRIMARY one.
|
||||
* For now, use a hard-coded sanity limit of 1Mb of data.
|
||||
*/
|
||||
#if (defined(FEAT_X11) && defined(FEAT_CLIPBOARD)) || defined(PROTO)
|
||||
void
|
||||
x11_export_final_selection(void)
|
||||
{
|
||||
Display *dpy;
|
||||
char_u *str = NULL;
|
||||
long_u len = 0;
|
||||
int motion_type = -1;
|
||||
|
||||
# ifdef FEAT_GUI
|
||||
if (gui.in_use)
|
||||
dpy = X_DISPLAY;
|
||||
else
|
||||
# endif
|
||||
# ifdef FEAT_XCLIPBOARD
|
||||
dpy = xterm_dpy;
|
||||
# else
|
||||
return;
|
||||
# endif
|
||||
|
||||
// Get selection to export
|
||||
if (clip_plus.owned)
|
||||
motion_type = clip_convert_selection(&str, &len, &clip_plus);
|
||||
else if (clip_star.owned)
|
||||
motion_type = clip_convert_selection(&str, &len, &clip_star);
|
||||
|
||||
// Check it's OK
|
||||
if (dpy != NULL && str != NULL && motion_type >= 0
|
||||
&& len < 1024*1024 && len > 0)
|
||||
{
|
||||
int ok = TRUE;
|
||||
|
||||
// The CUT_BUFFER0 is supposed to always contain latin1. Convert from
|
||||
// 'enc' when it is a multi-byte encoding. When 'enc' is an 8-bit
|
||||
// encoding conversion usually doesn't work, so keep the text as-is.
|
||||
if (has_mbyte)
|
||||
{
|
||||
vimconv_T vc;
|
||||
|
||||
vc.vc_type = CONV_NONE;
|
||||
if (convert_setup(&vc, p_enc, (char_u *)"latin1") == OK)
|
||||
{
|
||||
int intlen = len;
|
||||
char_u *conv_str;
|
||||
|
||||
vc.vc_fail = TRUE;
|
||||
conv_str = string_convert(&vc, str, &intlen);
|
||||
len = intlen;
|
||||
if (conv_str != NULL)
|
||||
{
|
||||
vim_free(str);
|
||||
str = conv_str;
|
||||
}
|
||||
else
|
||||
{
|
||||
ok = FALSE;
|
||||
}
|
||||
convert_setup(&vc, NULL, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
ok = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// Do not store the string if conversion failed. Better to use any
|
||||
// other selection than garbled text.
|
||||
if (ok)
|
||||
{
|
||||
XStoreBuffer(dpy, (char *)str, (int)len, 0);
|
||||
XFlush(dpy);
|
||||
}
|
||||
}
|
||||
|
||||
vim_free(str);
|
||||
}
|
||||
#endif
|
||||
#endif // FEAT_CLIPBOARD || PROTO
|
||||
|
||||
void
|
||||
clear_oparg(oparg_T *oap)
|
||||
{
|
||||
|
Reference in New Issue
Block a user