[gspell/wip/fix-constant-redrawing] inline-checker-text-buffer: fix constant redrawing



commit cc4ff3276a34622e4f3374b72a6bb480aba24d38
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sat Jul 9 13:56:19 2016 +0200

    inline-checker-text-buffer: fix constant redrawing
    
    When check_current_word was FALSE, the GtkTextView was constantly
    redrawn. For two reasons:
    - because gtk_text_buffer_remove_tag() was called on the current word,
      even if the tag was not present. Which always queued a redraw.
    - because of the queue_draw() hack, which was also always called when
      check_current_word is FALSE.
    
    So, for the current word handling, do the queue_draw() hack only if the
    tag is removed. And remove the tag only if the tag is present.
    
    Thanks to Sebastian Keller for the bug report.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=768306

 gspell/gspell-inline-checker-text-buffer.c |   76 +++++++++++++++++++++-------
 1 files changed, 57 insertions(+), 19 deletions(-)
---
diff --git a/gspell/gspell-inline-checker-text-buffer.c b/gspell/gspell-inline-checker-text-buffer.c
index 2da0e00..fab18de 100644
--- a/gspell/gspell-inline-checker-text-buffer.c
+++ b/gspell/gspell-inline-checker-text-buffer.c
@@ -287,6 +287,49 @@ get_current_word_boundaries (GtkTextBuffer *buffer,
                !gtk_text_iter_equal (current_word_end, &insert_iter));
 }
 
+/* FIXME properly. Workaround for bug in GtkTextView:
+ * https://bugzilla.gnome.org/show_bug.cgi?id=763741
+ */
+static void
+hack_queue_draw (GtkTextView *view)
+{
+       if (view != NULL)
+       {
+               gtk_widget_queue_draw (GTK_WIDGET (view));
+       }
+}
+
+static void
+remove_tag_if_present (GtkTextView       *view,
+                      GtkTextBuffer     *buffer,
+                      GtkTextTag        *tag,
+                      const GtkTextIter *start,
+                      const GtkTextIter *end)
+{
+       gboolean remove = FALSE;
+
+       if (gtk_text_iter_has_tag (start, tag))
+       {
+               remove = TRUE;
+       }
+       else
+       {
+               GtkTextIter iter = *start;
+
+               if (gtk_text_iter_forward_to_tag_toggle (&iter, tag) &&
+                   gtk_text_iter_compare (&iter, end) < 0)
+               {
+                       remove = TRUE;
+               }
+       }
+
+       if (remove)
+       {
+               gtk_text_buffer_remove_tag (buffer, tag, start, end);
+               hack_queue_draw (view);
+       }
+}
+
 static void
 check_visible_region_in_view (GspellInlineCheckerTextBuffer *spell,
                              GtkTextView                   *view)
@@ -315,8 +358,9 @@ check_visible_region_in_view (GspellInlineCheckerTextBuffer *spell,
                                              &visible_start,
                                              &visible_end);
 
-       if (intersect == NULL)
+       if (_gspell_region_is_empty (intersect))
        {
+               g_clear_object (&intersect);
                return;
        }
 
@@ -329,10 +373,11 @@ check_visible_region_in_view (GspellInlineCheckerTextBuffer *spell,
                                                 &current_word_start,
                                                 &current_word_end))
                {
-                       gtk_text_buffer_remove_tag (spell->buffer,
-                                                   spell->highlight_tag,
-                                                   &current_word_start,
-                                                   &current_word_end);
+                       remove_tag_if_present (view,
+                                              spell->buffer,
+                                              spell->highlight_tag,
+                                              &current_word_start,
+                                              &current_word_end);
 
                        _gspell_region_subtract (intersect,
                                                 &current_word_start,
@@ -344,13 +389,13 @@ check_visible_region_in_view (GspellInlineCheckerTextBuffer *spell,
                        _gspell_region_add (spell->scan_region,
                                            &current_word_start,
                                            &current_word_end);
-               }
-       }
 
-       if (_gspell_region_is_empty (intersect))
-       {
-               g_clear_object (&intersect);
-               goto out;
+                       if (_gspell_region_is_empty (intersect))
+                       {
+                               g_clear_object (&intersect);
+                               return;
+                       }
+               }
        }
 
        _gspell_region_get_start_region_iter (intersect, &intersect_iter);
@@ -391,14 +436,7 @@ check_visible_region_in_view (GspellInlineCheckerTextBuffer *spell,
                g_clear_object (&spell->scan_region);
        }
 
-out:
-       if (view != NULL)
-       {
-               /* FIXME properly. Workaround for bug in GtkTextView:
-                * https://bugzilla.gnome.org/show_bug.cgi?id=763741
-                */
-               gtk_widget_queue_draw (GTK_WIDGET (view));
-       }
+       hack_queue_draw (view);
 }
 
 static void


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