[gtksourceview/wip/regex-search] Search: fix bug in forward/backward search



commit 785aadc12607b0cfa34f7e0c634f86b4d9ad5ec4
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Mon Jul 22 11:37:51 2013 +0200

    Search: fix bug in forward/backward search
    
    All unit tests pass. But async forward/backward search have still the
    same bug (more unit tests need to be written).

 gtksourceview/gtksourcesearch.c |   38 ++++++++++++++++++++++++++++----------
 1 files changed, 28 insertions(+), 10 deletions(-)
---
diff --git a/gtksourceview/gtksourcesearch.c b/gtksourceview/gtksourcesearch.c
index 15f057b..1b7f47c 100644
--- a/gtksourceview/gtksourcesearch.c
+++ b/gtksourceview/gtksourcesearch.c
@@ -1935,33 +1935,42 @@ smart_forward_search_step (GtkSourceSearch *search,
 {
        GtkTextIter iter = *start_at;
        GtkTextIter limit;
+       GtkTextIter region_start = *start_at;
        GtkTextRegion *region = NULL;
 
        if (!gtk_text_iter_has_tag (&iter, search->priv->found_tag))
        {
                gtk_text_iter_forward_to_tag_toggle (&iter, search->priv->found_tag);
        }
+       else if (!gtk_text_iter_begins_tag (&iter, search->priv->found_tag))
+       {
+               gtk_text_iter_backward_to_tag_toggle (&iter, search->priv->found_tag);
+               region_start = iter;
+       }
 
        limit = iter;
        gtk_text_iter_forward_to_tag_toggle (&limit, search->priv->found_tag);
 
        if (search->priv->scan_region != NULL)
        {
-               region = gtk_text_region_intersect (search->priv->scan_region, start_at, &limit);
+               region = gtk_text_region_intersect (search->priv->scan_region, &region_start, &limit);
        }
 
        if (is_text_region_empty (region))
        {
-               gboolean found = basic_forward_search (search, &iter, match_start, match_end, &limit);
-
                if (region != NULL)
                {
                        gtk_text_region_destroy (region, TRUE);
                }
 
-               if (found)
+               while (basic_forward_search (search, &iter, match_start, match_end, &limit))
                {
-                       return TRUE;
+                       if (gtk_text_iter_compare (start_at, match_start) <= 0)
+                       {
+                               return TRUE;
+                       }
+
+                       iter = *match_end;
                }
 
                *start_at = limit;
@@ -2012,6 +2021,7 @@ smart_backward_search_step (GtkSourceSearch *search,
 {
        GtkTextIter iter = *start_at;
        GtkTextIter limit;
+       GtkTextIter region_end = *start_at;
        GtkTextRegion *region = NULL;
 
        if (gtk_text_iter_begins_tag (&iter, search->priv->found_tag) ||
@@ -2020,27 +2030,35 @@ smart_backward_search_step (GtkSourceSearch *search,
        {
                gtk_text_iter_backward_to_tag_toggle (&iter, search->priv->found_tag);
        }
+       else if (gtk_text_iter_has_tag (&iter, search->priv->found_tag))
+       {
+               gtk_text_iter_forward_to_tag_toggle (&iter, search->priv->found_tag);
+               region_end = iter;
+       }
 
        limit = iter;
        gtk_text_iter_backward_to_tag_toggle (&limit, search->priv->found_tag);
 
        if (search->priv->scan_region != NULL)
        {
-               region = gtk_text_region_intersect (search->priv->scan_region, &limit, start_at);
+               region = gtk_text_region_intersect (search->priv->scan_region, &limit, &region_end);
        }
 
        if (is_text_region_empty (region))
        {
-               gboolean found = basic_backward_search (search, &iter, match_start, match_end, &limit);
-
                if (region != NULL)
                {
                        gtk_text_region_destroy (region, TRUE);
                }
 
-               if (found)
+               while (basic_backward_search (search, &iter, match_start, match_end, &limit))
                {
-                       return TRUE;
+                       if (gtk_text_iter_compare (match_end, start_at) <= 0)
+                       {
+                               return TRUE;
+                       }
+
+                       iter = *match_start;
                }
 
                *start_at = limit;


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