0
0
mirror of https://github.com/vim/vim.git synced 2025-09-25 03:54:15 -04:00

updated for version 7.3.856

Problem:    When calling system() multi-byte clipboard contents is garbled.
Solution:   Save and restore the clipboard contents.  (Yukihiro Nakadaira)
This commit is contained in:
Bram Moolenaar
2013-03-13 17:50:25 +01:00
parent b3cb982162
commit 1a0316ca2a
8 changed files with 101 additions and 6 deletions

View File

@@ -1138,6 +1138,11 @@ sigcont_handler SIGDEFARG(sigarg)
# if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
static void loose_clipboard __ARGS((void));
static void save_clipboard __ARGS((void));
static void restore_clipboard __ARGS((void));
static void *clip_star_save = NULL;
static void *clip_plus_save = NULL;
/*
* Called when Vim is going to sleep or execute a shell command.
@@ -1158,6 +1163,42 @@ loose_clipboard()
XFlush(x11_display);
}
}
/*
* Save clipboard text to restore later.
*/
static void
save_clipboard()
{
if (clip_star.owned)
clip_star_save = get_register('*', TRUE);
if (clip_plus.owned)
clip_plus_save = get_register('+', TRUE);
}
/*
* Restore clipboard text if no one own the X selection.
*/
static void
restore_clipboard()
{
if (clip_star_save != NULL)
{
if (!clip_gen_owner_exists(&clip_star))
put_register('*', clip_star_save);
else
free_register(clip_star_save);
clip_star_save = NULL;
}
if (clip_plus_save != NULL)
{
if (!clip_gen_owner_exists(&clip_plus))
put_register('+', clip_plus_save);
else
free_register(clip_plus_save);
clip_plus_save = NULL;
}
}
#endif
/*
@@ -3844,6 +3885,7 @@ mch_call_shell(cmd, options)
settmode(TMODE_COOK); /* set to normal mode */
# if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
save_clipboard();
loose_clipboard();
# endif
@@ -3916,6 +3958,9 @@ mch_call_shell(cmd, options)
settmode(TMODE_RAW); /* set to raw mode */
# ifdef FEAT_TITLE
resettitle();
# endif
# if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
restore_clipboard();
# endif
return x;
@@ -3965,6 +4010,9 @@ mch_call_shell(cmd, options)
settmode(TMODE_COOK); /* set to normal mode */
# if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
/* Disown the clipboard, because is the executed command tries to obtain a
* selection and we own it we get a deadlock. */
save_clipboard();
loose_clipboard();
# endif
@@ -4835,6 +4883,9 @@ error:
settmode(TMODE_RAW); /* set to raw mode */
# ifdef FEAT_TITLE
resettitle();
# endif
# if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
restore_clipboard();
# endif
vim_free(newcmd);