[gtk/dnd-gestures-2: 224/242] text: Fix dragging of text across focus changes



commit 0b9daefb761125db164f741755b73bae5db5dc4a
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Jan 7 00:26:30 2020 -0500

    text: Fix dragging of text across focus changes
    
    When dragging selected text from an entry over a stackswitcher
    to show a different page, the focus changes, causing the selection
    to be lost; we should not lose the dragged content in this case.

 gtk/gtktext.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
---
diff --git a/gtk/gtktext.c b/gtk/gtktext.c
index 1304a29f9c..9d2c690d76 100644
--- a/gtk/gtktext.c
+++ b/gtk/gtktext.c
@@ -2845,6 +2845,8 @@ gtk_text_drag_gesture_update (GtkGestureDrag *gesture,
           GdkDragAction actions;
           GdkDrag *drag;
           GdkPaintable *paintable;
+          GdkContentProvider *content;
+          GValue value = G_VALUE_INIT;
 
           text = _gtk_text_get_selected_text (self);
           gtk_text_get_pixel_ranges (self, &ranges, &n_ranges);
@@ -2854,12 +2856,18 @@ gtk_text_drag_gesture_update (GtkGestureDrag *gesture,
           else
             actions = GDK_ACTION_COPY;
 
+          g_value_init (&value, G_TYPE_STRING);
+          g_value_set_string (&value, text);
+          content = gdk_content_provider_new_for_value (&value);
+          g_value_unset (&value);
+
           drag = gdk_drag_begin (gdk_event_get_surface ((GdkEvent*) event),
                                  gdk_event_get_device ((GdkEvent*) event),
-                                 priv->selection_content,
+                                 content,
                                  actions,
                                  priv->drag_start_x,
                                  priv->drag_start_y);
+          g_object_unref (content);
 
           g_signal_connect (drag, "dnd-finished", G_CALLBACK (dnd_finished_cb), self);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]