[gnome-builder] editor: keep search context around when there are matches



commit ac7b8f360d03f82f18504ce99527b23ea4698150
Author: Christian Hergert <chergert redhat com>
Date:   Mon Aug 7 12:16:08 2017 -0700

    editor: keep search context around when there are matches
    
    We might need to keep the search context around so that we can perform
    next/previous match actions via keybindings. That adds a bit of overhead
    in some cases, so we try to detect a few of those and still cleanup the
    context when possible.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=785934

 libide/editor/ide-editor-view.c |   34 ++++++++++++++++++++++++----------
 1 files changed, 24 insertions(+), 10 deletions(-)
---
diff --git a/libide/editor/ide-editor-view.c b/libide/editor/ide-editor-view.c
index fdd3274..cb8caa2 100644
--- a/libide/editor/ide-editor-view.c
+++ b/libide/editor/ide-editor-view.c
@@ -478,25 +478,39 @@ search_revealer_notify_reveal_child (IdeEditorView *self,
   if (!gtk_revealer_get_reveal_child (revealer))
     {
       /*
-       * Cancel any pending work by the context and release it. We don't need
-       * to hold onto these when they aren't being used because they handle
-       * buffer signals and other extraneous operations.
+       * Clear the context from the search bar so it doesn't try to
+       * keep updating various UI bits while the bar is not visible.
        */
       ide_editor_search_bar_set_context (self->search_bar, NULL);
-      g_clear_object (&self->search_context);
+
+      /*
+       * If there are no occurrences currently, just destroy the search context
+       * so that we can avoid tracking buffer changes.
+       */
+      if (self->search_context != NULL &&
+          gtk_source_search_context_get_occurrences_count (self->search_context) <= 0)
+        g_clear_object (&self->search_context);
+
+      /*
+       * We might still need the search context so the user can move to the
+       * prev/next search result. However, we do not any longer need to have
+       * highlight enabled.
+       */
+      if (self->search_context != NULL)
+        gtk_source_search_context_set_highlight (self->search_context, FALSE);
 
       /* Restore completion that we blocked below. */
       gtk_source_completion_unblock_interactive (completion);
     }
   else
     {
-      g_assert (self->search_context == NULL);
+      if (self->search_context == NULL)
+        self->search_context = g_object_new (GTK_SOURCE_TYPE_SEARCH_CONTEXT,
+                                             "buffer", self->buffer,
+                                             "settings", self->search_settings,
+                                             NULL);
 
-      self->search_context = g_object_new (GTK_SOURCE_TYPE_SEARCH_CONTEXT,
-                                           "buffer", self->buffer,
-                                           "highlight", TRUE,
-                                           "settings", self->search_settings,
-                                           NULL);
+      gtk_source_search_context_set_highlight (self->search_context, TRUE);
       ide_editor_search_bar_set_context (self->search_bar, self->search_context);
 
       /*


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