[gtksourceview] Bracket matching: remove another no-longer-needed hack



commit 39827342a3907bb5a1464ce58501cdba86f6c17e
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sat Oct 24 15:55:35 2015 +0200

    Bracket matching: remove another no-longer-needed hack
    
    gtk_source_buffer_set_highlight_matching_brackets() is no longer called
    in init(). The value is simply set to TRUE, which is sufficient, since
    at that time the buffer is empty, and when some text will be inserted,
    the cursor_moved() function will be called.
    
    Anyway, add a unit test to try to set the "highlight-matching-brackets"
    property before "tag-table", but it looks like the GTK+ properties are
    set before the GtkSourceView ones, so basically it's impossible for
    gtk_source_buffer_set_highlight_matching_brackets() to be called before
    the tag-table is set. If that changes in the future, the unit test is
    there.

 gtksourceview/gtksourcebuffer.c |   13 +------------
 tests/test-buffer.c             |   21 +++++++++++++++++++++
 2 files changed, 22 insertions(+), 12 deletions(-)
---
diff --git a/gtksourceview/gtksourcebuffer.c b/gtksourceview/gtksourcebuffer.c
index c4055b9..527286a 100644
--- a/gtksourceview/gtksourcebuffer.c
+++ b/gtksourceview/gtksourcebuffer.c
@@ -196,7 +196,6 @@ struct _GtkSourceBufferPrivate
 
        guint highlight_syntax : 1;
        guint highlight_brackets : 1;
-       guint constructed : 1;
        guint implicit_trailing_newline : 1;
 };
 
@@ -246,9 +245,6 @@ gtk_source_buffer_constructed (GObject *object)
 {
        GtkSourceBuffer *buffer = GTK_SOURCE_BUFFER (object);
 
-       /* we need to know that the tag-table was set */
-       buffer->priv->constructed = TRUE;
-
        if (buffer->priv->undo_manager == NULL)
        {
                /* This will install the default undo manager */
@@ -1492,14 +1488,7 @@ gtk_source_buffer_set_highlight_matching_brackets (GtkSourceBuffer *buffer,
        {
                buffer->priv->highlight_brackets = highlight;
 
-               /* try to see if there is already a bracket match at the
-                * current position, but only if the tag table is already set
-                * otherwise we have problems when calling this function
-                * on init (get_insert creates the tag table as a side effect */
-               if (buffer->priv->constructed)
-               {
-                       cursor_moved (buffer);
-               }
+               cursor_moved (buffer);
 
                g_object_notify (G_OBJECT (buffer), "highlight-matching-brackets");
        }
diff --git a/tests/test-buffer.c b/tests/test-buffer.c
index 60eecc0..07d5727 100644
--- a/tests/test-buffer.c
+++ b/tests/test-buffer.c
@@ -336,6 +336,7 @@ test_bracket_matching (void)
        GtkSourceBuffer *buffer;
        GtkSourceLanguageManager *language_manager;
        GtkSourceLanguage *c_language;
+       GtkTextTagTable *table;
 
        buffer = gtk_source_buffer_new (NULL);
 
@@ -404,6 +405,26 @@ test_bracket_matching (void)
        do_test_bracket_matching (buffer, "/*(*/\"a\"/*)*/", 10, -1, -1, GTK_SOURCE_BRACKET_MATCH_NOT_FOUND);
 
        g_object_unref (buffer);
+
+       /* Test setting the property and a specific tag table. There was a
+        * hack in the implementation to avoid trying to match brackets before
+        * the tag-table property is set. But now the hack is no longer needed.
+        */
+       table = gtk_text_tag_table_new ();
+
+       buffer = g_object_new (GTK_SOURCE_TYPE_BUFFER,
+                              "highlight-matching-brackets", FALSE,
+                              "tag-table", table,
+                              NULL);
+       g_object_unref (buffer);
+
+       buffer = g_object_new (GTK_SOURCE_TYPE_BUFFER,
+                              "highlight-matching-brackets", TRUE,
+                              "tag-table", table,
+                              NULL);
+       g_object_unref (buffer);
+
+       g_object_unref (table);
 }
 
 int


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