[gtksourceview/wip/regex-search] Search: fix bug in occurrence position



commit b0f358d36a7dd4a74f4e5779707dc6ccf9e94f3a
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Tue Jul 23 15:21:29 2013 +0200

    Search: fix bug in occurrence position

 gtksourceview/gtksourcesearch.c |   29 +++++++++++++++++++++--------
 1 files changed, 21 insertions(+), 8 deletions(-)
---
diff --git a/gtksourceview/gtksourcesearch.c b/gtksourceview/gtksourcesearch.c
index e621489..9426703 100644
--- a/gtksourceview/gtksourcesearch.c
+++ b/gtksourceview/gtksourcesearch.c
@@ -1253,11 +1253,15 @@ smart_forward_search_without_scanning (GtkSourceSearch   *search,
                                       GtkTextIter       *match_end,
                                       const GtkTextIter *stop_at)
 {
-       GtkTextIter iter = *start_at;
+       GtkTextIter iter;
 
        g_assert (start_at != NULL);
+       g_assert (match_start != NULL);
+       g_assert (match_end != NULL);
        g_assert (stop_at != NULL);
 
+       iter = *start_at;
+
        if (search->priv->text == NULL)
        {
                return FALSE;
@@ -1276,6 +1280,10 @@ smart_forward_search_without_scanning (GtkSourceSearch   *search,
                {
                        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);
+               }
 
                limit = iter;
                gtk_text_iter_forward_to_tag_toggle (&limit, search->priv->found_tag);
@@ -1285,9 +1293,14 @@ smart_forward_search_without_scanning (GtkSourceSearch   *search,
                        limit = *stop_at;
                }
 
-               if (basic_forward_search (search, &iter, match_start, match_end, &limit))
+               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;
                }
 
                iter = limit;
@@ -2644,11 +2657,11 @@ _gtk_source_search_get_occurrence_position (GtkSourceSearch   *search,
 
        /* Verify that the occurrence is correct. */
 
-       found = basic_forward_search (search,
-                                     match_start,
-                                     &m_start,
-                                     &m_end,
-                                     match_end);
+       found = smart_forward_search_without_scanning (search,
+                                                      match_start,
+                                                      &m_start,
+                                                      &m_end,
+                                                      match_end);
 
        if (!found ||
            !gtk_text_iter_equal (match_start, &m_start) ||


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