[gtk/matthiasc/for-master: 2/4] textview: Fix placement of Emoji chooser




commit 9512e461d5cd3c0473156f821a45c6ac38535438
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Sep 2 08:04:15 2020 -0400

    textview: Fix placement of Emoji chooser
    
    If the selection extends beyond the visible range,
    place the Emoji chooser over the center of the window.
    
    Fixes: #3109

 gtk/gtktextview.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
---
diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c
index 13938c4cb6..06caf5e3ee 100644
--- a/gtk/gtktextview.c
+++ b/gtk/gtktextview.c
@@ -9623,6 +9623,7 @@ gtk_text_view_insert_emoji (GtkTextView *text_view)
   GtkWidget *chooser;
   GtkTextIter iter;
   GdkRectangle rect;
+  GdkRectangle rect2;
   GtkTextBuffer *buffer;
 
   if (gtk_widget_get_ancestor (GTK_WIDGET (text_view), GTK_TYPE_EMOJI_CHOOSER) != NULL)
@@ -9639,6 +9640,7 @@ gtk_text_view_insert_emoji (GtkTextView *text_view)
     }
 
   buffer = get_buffer (text_view);
+
   gtk_text_buffer_get_iter_at_mark (buffer, &iter,
                                     gtk_text_buffer_get_insert (buffer));
 
@@ -9646,6 +9648,18 @@ gtk_text_view_insert_emoji (GtkTextView *text_view)
   gtk_text_view_buffer_to_window_coords (text_view, GTK_TEXT_WINDOW_TEXT,
                                          rect.x, rect.y, &rect.x, &rect.y);
   _text_window_to_widget_coords (text_view, &rect.x, &rect.y);
+  gtk_text_view_get_visible_rect (text_view, &rect2);
+  gtk_text_view_buffer_to_window_coords (text_view, GTK_TEXT_WINDOW_TEXT,
+                                         rect2.x, rect2.y, &rect2.x, &rect2.y);
+  _text_window_to_widget_coords (text_view, &rect2.x, &rect2.y);
+
+  if (!gdk_rectangle_intersect (&rect2, &rect, &rect))
+    {
+      rect.x = rect2.width / 2;
+      rect.y = rect2.height / 2;
+      rect.width = 0;
+      rect.height = 0;
+    }
 
   gtk_popover_set_pointing_to (GTK_POPOVER (chooser), &rect);
 


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