[gnome-builder] sourceview: re-apply .has-selection after restoring context



commit bf9b0936c1ca5a319151dd06d258006a11c3f480
Author: Christian Hergert <chergert redhat com>
Date:   Thu Jul 15 16:26:35 2021 -0700

    sourceview: re-apply .has-selection after restoring context
    
    Related to !402

 src/libide/sourceview/ide-source-view-mode.c | 28 +++++++++++++++++++++-------
 1 file changed, 21 insertions(+), 7 deletions(-)
---
diff --git a/src/libide/sourceview/ide-source-view-mode.c b/src/libide/sourceview/ide-source-view-mode.c
index fc9b2366f..724a328a4 100644
--- a/src/libide/sourceview/ide-source-view-mode.c
+++ b/src/libide/sourceview/ide-source-view-mode.c
@@ -39,6 +39,7 @@ struct _IdeSourceViewMode
   char                  *display_name;
   gchar                 *default_mode;
   IdeSourceViewModeType  type;
+  guint                  has_selection : 1;
 };
 
 G_DEFINE_TYPE (IdeSourceViewMode, ide_source_view_mode, GTK_TYPE_WIDGET)
@@ -51,6 +52,21 @@ enum {
 
 static GParamSpec *properties [LAST_PROP];
 
+static void
+update_selection (IdeSourceViewMode *self)
+{
+  GtkStyleContext *style_context;
+
+  g_assert (IDE_IS_SOURCE_VIEW_MODE (self));
+
+  style_context = gtk_widget_get_style_context (GTK_WIDGET (self));
+
+  if (self->has_selection)
+    gtk_style_context_add_class (style_context, "has-selection");
+  else
+    gtk_style_context_remove_class (style_context, "has-selection");
+}
+
 static void
 get_param (IdeSourceViewMode *self,
            const gchar       *param,
@@ -496,6 +512,9 @@ _ide_source_view_mode_do_event (IdeSourceViewMode *mode,
   gtk_style_context_restore (context);
   g_object_unref (context);
 
+  /* possibly re-apply has_selection */
+  update_selection (mode);
+
   *remove = FALSE;
   switch (mode->type)
     {
@@ -603,14 +622,9 @@ void
 ide_source_view_mode_set_has_selection (IdeSourceViewMode *self,
                                         gboolean           has_selection)
 {
-  GtkStyleContext *style_context;
-
   g_assert (IDE_IS_SOURCE_VIEW_MODE (self));
 
-  style_context = gtk_widget_get_style_context (GTK_WIDGET (self));
+  self->has_selection = !!has_selection;
 
-  if (has_selection)
-    gtk_style_context_add_class (style_context, "has-selection");
-  else
-    gtk_style_context_remove_class (style_context, "has-selection");
+  update_selection (self);
 }


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