diff --git a/terminal/terminal-screen.c b/terminal/terminal-screen.c index dc5c85f4..428dae49 100644 --- a/terminal/terminal-screen.c +++ b/terminal/terminal-screen.c @@ -165,7 +165,8 @@ static void terminal_screen_set_tab_label_color (TerminalScreen static GtkWidget* terminal_screen_unsafe_paste_dialog_new (TerminalScreen *screen, const gchar *text); static void terminal_screen_paste_unsafe_text (TerminalScreen *screen, - const gchar *text); + const gchar *text, + GdkAtom original_clipboard); @@ -1789,8 +1790,11 @@ terminal_screen_unsafe_paste_dialog_new (TerminalScreen *screen, static void terminal_screen_paste_unsafe_text (TerminalScreen *screen, - const gchar *text) + const gchar *text, + GdkAtom original_clipboard) { + terminal_return_if_fail(original_clipboard != GDK_SELECTION_CLIPBOARD && original_clipboard != GDK_SELECTION_PRIMARY); + GtkWidget *dialog = terminal_screen_unsafe_paste_dialog_new (screen, text); gtk_widget_show_all (dialog); @@ -1804,6 +1808,7 @@ terminal_screen_paste_unsafe_text (TerminalScreen *screen, GtkTextView *tv = GTK_TEXT_VIEW (gtk_bin_get_child (GTK_BIN (sw))); GtkTextBuffer *buffer = gtk_text_view_get_buffer (tv); GtkTextIter start, end; + GtkClipboard *clipboard; char *res_text; gtk_text_buffer_get_bounds (buffer, &start, &end); @@ -1811,13 +1816,18 @@ terminal_screen_paste_unsafe_text (TerminalScreen *screen, if (res_text != NULL) { - /* convert LF to CR before feeding: see https://gitlab.gnome.org/GNOME/vte/issues/106 */ - size_t i; - for (i = 0; i < strlen (res_text); ++i) - if (res_text[i] == '\x0A') - res_text[i] = '\x0D'; + /* modify the content of the clipboard as required, and then paste it. + * Using the builtin pasting function enabled bracketed paste mode when applicable. + */ + clipboard = gtk_clipboard_get(original_clipboard); + gtk_clipboard_set_text(clipboard, res_text, strlen (res_text)); + + if (original_clipboard == GDK_SELECTION_CLIPBOARD) { + vte_terminal_paste_clipboard(VTE_TERMINAL (screen->terminal)); + } else { + vte_terminal_paste_primary(VTE_TERMINAL (screen->terminal)); + } - vte_terminal_feed_child (VTE_TERMINAL (screen->terminal), res_text, strlen (res_text)); g_free (res_text); } } @@ -2458,7 +2468,7 @@ terminal_screen_paste_clipboard (TerminalScreen *screen) g_object_get (G_OBJECT (screen->preferences), "misc-show-unsafe-paste-dialog", &show_dialog, NULL); if (show_dialog && terminal_screen_is_text_unsafe (text)) - terminal_screen_paste_unsafe_text (screen, text); + terminal_screen_paste_unsafe_text (screen, text, GDK_SELECTION_CLIPBOARD); else vte_terminal_paste_clipboard (VTE_TERMINAL (screen->terminal)); @@ -2487,7 +2497,7 @@ terminal_screen_paste_primary (TerminalScreen *screen) g_object_get (G_OBJECT (screen->preferences), "misc-show-unsafe-paste-dialog", &show_dialog, NULL); if (show_dialog && terminal_screen_is_text_unsafe (text)) - terminal_screen_paste_unsafe_text (screen, text); + terminal_screen_paste_unsafe_text (screen, text, GDK_SELECTION_PRIMARY); else vte_terminal_paste_primary (VTE_TERMINAL (screen->terminal));