diff -Nurw leafpad-0.8.18.1.orig/src/main.c leafpad-0.8.18.1/src/main.c --- leafpad-0.8.18.1.orig/src/main.c 2009-10-24 10:38:34.000000000 +0800 +++ leafpad-0.8.18.1/src/main.c 2013-12-25 16:23:30.066306128 +0800 @@ -29,6 +29,8 @@ # include #endif +GtkClipboard *selection_primary = NULL; + typedef struct { gint width; gint height; @@ -297,6 +299,8 @@ gtk_init(&argc, &argv); g_set_application_name(PACKAGE_NAME); + selection_primary = gtk_clipboard_get(GDK_SELECTION_PRIMARY); + #if !GTK_CHECK_VERSION(2, 6, 0) add_about_stock(); #endif diff -Nurw leafpad-0.8.18.1.orig/src/view.c leafpad-0.8.18.1/src/view.c --- leafpad-0.8.18.1.orig/src/view.c 2008-12-18 06:24:59.000000000 +0800 +++ leafpad-0.8.18.1/src/view.c 2013-12-25 16:33:24.882300900 +0800 @@ -24,6 +24,9 @@ static gint keyval; static gboolean view_scroll_flag = FALSE; +extern GtkClipboard *selection_primary; +gchar *selection_primary_str = NULL; + gint get_current_keyval(void) { return keyval; @@ -212,6 +215,16 @@ gtk_text_buffer_place_cursor(buffer, &iter); } + // backup and restore the clipboard + gchar *current_clipboard_str = gtk_clipboard_wait_for_text(selection_primary); + if ((current_clipboard_str == NULL) || (current_clipboard_str[0]=='\0')) { + gtk_clipboard_set_text(selection_primary, selection_primary_str, -1); + } + else { + g_free(selection_primary_str); + selection_primary_str = g_strdup(current_clipboard_str); + } + return FALSE; }