[gtksourceview] styleschemepreview: lookup fallback styles



commit 4f70fbabb31339c824455cc74b966daf4f7f2d84
Author: Christian Hergert <chergert redhat com>
Date:   Wed Oct 13 19:49:58 2021 -0700

    styleschemepreview: lookup fallback styles
    
    If we fail to locate a style within a scheme, we can check for the
    fallback.
    
    Fixes #187

 gtksourceview/gtksourcestyleschemepreview.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
---
diff --git a/gtksourceview/gtksourcestyleschemepreview.c b/gtksourceview/gtksourcestyleschemepreview.c
index 39de94c8..83002106 100644
--- a/gtksourceview/gtksourcestyleschemepreview.c
+++ b/gtksourceview/gtksourcestyleschemepreview.c
@@ -28,6 +28,8 @@
 #endif
 
 #include "gtksourcebuffer.h"
+#include "gtksourcelanguage.h"
+#include "gtksourcelanguagemanager.h"
 #include "gtksourcestyle.h"
 #include "gtksourcestylescheme.h"
 #include "gtksourcestyleschemepreview.h"
@@ -200,9 +202,11 @@ add_text (GtkSourceBuffer      *buffer,
                { "    ", NULL },
                { "XXXXXXXX", "def:identifier" },
        };
+       GtkSourceLanguage *def;
        GHashTable *tags;
        GtkTextIter iter;
 
+       def = gtk_source_language_manager_get_language (gtk_source_language_manager_get_default (), "def");
        tags = g_hash_table_new (NULL, NULL);
 
        gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (buffer), &iter);
@@ -215,6 +219,16 @@ add_text (GtkSourceBuffer      *buffer,
                {
                        GtkSourceStyle *style = gtk_source_style_scheme_get_style (scheme, runs[i].style);
 
+                       if (style == NULL)
+                       {
+                               const char *fallback = gtk_source_language_get_style_fallback (def, 
runs[i].style);
+
+                               if (fallback != NULL)
+                               {
+                                       style = gtk_source_style_scheme_get_style (scheme, fallback);
+                               }
+                       }
+
                        if (style != NULL)
                        {
                                GtkTextTag *tag;


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